Is there a function to extract a 'column' from an array in PHP?

前端 未结 14 1410
鱼传尺愫
鱼传尺愫 2020-11-21 07:33

I have an array of arrays, with the following structure :

array(array(\'page\' => \'page1\', \'name\' => \'pagename1\')
      array(\'page\' => \'pa         


        
14条回答
  •  [愿得一人]
    2020-11-21 08:00

    As of PHP 5.5 you can use array_column():

     'page1', 'name' => 'pagename1'),
                array('page' => 'page2', 'name' => 'pagename2'),
                array('page' => 'page3', 'name' => 'pagename3')
                );
    $names = array_column($samples, 'name');
    print_r($names);
    

    See it in action

提交回复
热议问题