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"]
              }
         },
halfer
  • 19,824
  • 17
  • 99
  • 186
Amila Priyankara
  • 118
  • 1
  • 12
  • 1
    How did you tried to solve? – splash58 Nov 28 '17 at 10:06
  • 2
    Possible duplicate of [replace array keys with given respective keys](https://stackoverflow.com/questions/11722988/replace-array-keys-with-given-respective-keys) – splash58 Nov 28 '17 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?](//meta.stackoverflow.com/q/326569) - 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. – halfer Nov 28 '17 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); } } } – Amila Priyankara Nov 28 '17 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? – Nic3500 Nov 28 '17 at 12:45

1 Answers1

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.

Amila Priyankara
  • 118
  • 1
  • 12