fork download
  1. <?
  2. $first_array[0][] = 'User1';
  3. $first_array[0][] = 5;
  4. $first_array[1][] = 'User2';
  5. $first_array[1][] = 3;
  6.  
  7. $secnd_array[0][] = 3;
  8. $secnd_array[0][] = 10.00;
  9. $secnd_array[1][] = 5;
  10. $secnd_array[1][] = 47.00;
  11.  
  12. // Make the user_id the key of the array
  13. foreach ($secnd_array as $sca) {
  14. $searchable_second_array[ $sca[0] ] = $sca[1];
  15. }
  16. // Modify the original array
  17. array_walk($first_array, function(&$a) use ($searchable_second_array) {
  18. // Here we find the second element of the first array in the modified second array :p
  19. $a[] = $searchable_second_array[ $a[1] ];
  20. });
  21.  
  22. print_r($first_array);
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => User1
            [1] => 5
            [2] => 47
        )

    [1] => Array
        (
            [0] => User2
            [1] => 3
            [2] => 10
        )

)