Q:

adding string keys to inner arrays

I wish to add string keys to my inner PHP arrays.  So, I want to convert this:
array (size=2)
0 => array (size=3)
  0 => string 'X705' (length=4)
  1 => string 'X723' (length=4)
  2 => string 'Sue' (length=0)
1 => array (size=3)
  0 => string 'X714' (length=4)
  1 => string 'X721' (length=4)
  2 => string 'John' (length=0)

to this:
array (size=2)
0 => 
array (size=3)
  'code1' => string 'X705' (length=4)
  'code2' => string 'X723' (length=4)
  'name' => string 'Sue' (length=0)
1 => 
array (size=3)
  'code1' => string 'X714' (length=4)
  'code2' => string 'X721' (length=4)
  'name' => string 'John' (length=0)

I think I need to use array_walk but cannot fathom it out.  Any help appreciated. 

A:

You can use array_map for that purpose:
$newarray = array_map(function($x) {
    return array("code1" => $x[0], "code2" => $x[1], "name" => $x[2]);
}, $array); 

where $array is your input array.