Home  >  Q&A  >  body text

How to select only one column in an array

<p>I have an array like below in laravel and I want to extract the columns in it. </p> <pre class="brush:php;toolbar:false;">Array ( [0] => Array ( [table] => form_identification [column] => region ) [1] => Array ( [table] => form_identification [column] => province ) )</pre> <p>I want the output to be as follows</p> <pre class="brush:php;toolbar:false;">Array ( [0] => Array ( [column] => region ) [1] => Array ( [column] => province ) )</pre></p>
P粉410239819P粉410239819385 days ago476

reply all(1)I'll reply

  • P粉575055974

    P粉5750559742023-09-04 09:47:34

    Treat your first array as a $datas variable, we will use foreach to loop over the entire array

    foreach($datas as $data) {
        $result[] = array('column' => $data['column']);
    }
    print_r($result);
    

    reply
    0
  • Cancelreply