0

I hawe two arrays

array1:

Array ( [Arsenal] => 20 [Liverpool] => 1 
        [Chelsea] => 6 [Manchester City] => 1 
        [West Brom] => 1 [Swansea] => 2 
        [Leicester] => 2 [West Ham] => 2 
        [Tottenham] => 2 [Everton] => 2 [Crystal Palace] => 1 )

and

array2:

Array ( [Arsenal] => 19 [Liverpool] => 1 
        [Chelsea] => 2 [Leicester] => 1 
        [Everton] => 1 [Crystal Palace] => 1 [West Ham] => 1 )

Question is:
How to combine these arrays and print over in a while or for-each loop? I need to print this as a table where the first column is a team, the second column is a value from array1 and the third column is a value from array2.

gkrls
  • 2,618
  • 2
  • 15
  • 29
Sasa Jovic
  • 33
  • 1
  • 10

1 Answers1

0

this Could help you: Click me

array_map(function($a, $b) use (&$results) {

    $key = current(array_keys($a));
    $a[$key] = array('ip' => $a[$key]);

    // Obtain the key again as the second array may have a different key.
    $key = current(array_keys($b));
    $b[$key] = array('name' => $b[$key]);

    $results += array_merge_recursive($a, $b);

}, $array1, $array2);

var_dump($results);

or you can use array_merge_recursive function

Community
  • 1
  • 1
Idan Magled
  • 2,186
  • 1
  • 23
  • 33