How can I create an array from the values of another array's key?

前端 未结 4 757
走了就别回头了
走了就别回头了 2021-02-01 18:38

I have an array as follows:

$arr1 = array(
  0 => array(
    \'name\' => \'tom\',
    \'age\' => 22
  ),
  1 => array(
    \'name\' => \'nick\',
           


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 19:33

    $array = array(0 => array('name' => 'tom', 'age' => 22), 1 => array('name' => 'nick', 'age' => 18));
    foreach($array as $arr => $a){
        $names[] = $array[$arr]["name"];
    }
    
    print_r($names); //Array ( [0] => tom [1] => nick ) 
    

提交回复
热议问题