0

Match 1st and 2nd array associates keys. And replace 1st array associates keys with 2nd array value. Information like below.

1st Array

  [
        [ ],
        [ ],
       {
         585: {
               firsthalf: "0",
               secondhalf: "1",
               goals: "1",
               outcome: ["loss"]
              },
         625: {
               firsthalf: "2",
               secondhalf: "2",
               goals: "4",
               outcome: ["win"]
              }
         },
         {
          609: {
                firsthalf: "2",
                secondhalf: "0",
                goals: "2",
                outcome: ["win"]
               },
          625: {
                firsthalf: "0",
                secondhalf: "1",
                goals: "1",
                outcome: ["loss"]
               }
           },

2nd Array

       [
        {654: "North Geelong Warriors FC"},
        {645: "Springvale White Eagles FC"},
        {637: "Brunswick City Soccer Club"},
        {625: "Melbourne Victory Youth FC"},
        {585: "Moreland City FC"},

Final out come should be like this

Final Array
       [
        [ ],
        [ ],
       {
         Moreland City FC: {
               firsthalf: "0",
               secondhalf: "1",
               goals: "1",
               outcome: ["loss"]
              },
         Melbourne Victory Youth FC: {
               firsthalf: "2",
               secondhalf: "2",
               goals: "4",
               outcome: ["win"]
              }
         },
5
  • 1
    How did you tried to solve? Commented Nov 28, 2017 at 10:06
  • 2
    Possible duplicate of replace array keys with given respective keys Commented Nov 28, 2017 at 10:24
  • Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. Commented Nov 28, 2017 at 10:45
  • I have used below foreach for solution but need improvement on this foreach($1stArray as $keys => $values) { foreach($values as $key => $value){ for ($x = 0; $x <= count($2ndArray); $x++) { $newkey = array_search($key,$2ndArray[$x]); $newkey = $key; unset ($key); } } } Commented Nov 28, 2017 at 11:27
  • Put code in the question, not in the comments. It would also help if you explained the logic that produced the final array form the 1st one. Ex why is there only one entry for Melbource Victory Youth Fc, when they are listed twice (team 625) in the first one? Commented Nov 28, 2017 at 12:45

1 Answer 1

0
$newArray = array();
foreach($Array01 as $keys => $values){
foreach($values as $key => $value){
        for ($x = 0; $x <= count($array02); $x++) {
            if (array_search($key, $array02[$x])){
                $newkey = array_search($key,$array02[$x]);
                $newArray[] = array($newkey => $value);
      }
    }
  }
}
print_r($$newArray);

This is been sort it out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.