I have an array as follows:
$arr1 = array( 0 => array( \'name\' => \'tom\', \'age\' => 22 ), 1 => array( \'name\' => \'nick\',
This can be done in still more simple way by using array_column
$arr2= array_column($arr1, 'name'); print_r($arr2); //Array ( [0] => tom [1] => nick )
array_column is used to get the columns of a sub-array.