How to Get One Column in PHP Array?

03-Apr-2023

.

Admin

How to Get One Column in PHP Array?

Hi Dev,

This example is focused on how to get one column in a PHP array. This tutorial will give you a simple example of how to get one column in the array. it's a simple example of how to find one column in a PHP array. I’m going to show you how to find one column in the array.

Here, I will show you how to works how to get one column in a PHP array. let’s discuss how to get one column in the array. we will help you to give examples of how to find one column in a PHP array. let’s discuss how to find one column in the array. Follow bellow tutorial step on how to get a column in an array in PHP.

Example:


index.php

<?php

$array = array(

array(

'id' => 1,

'first_name' => 'Peter',

'last_name' => 'Griffin',

),

array(

'id' => 2,

'first_name' => 'Ben',

'last_name' => 'Smith',

),

array(

'id' => 3,

'first_name' => 'Joe',

'last_name' => 'Doe',

)

);

$first_names = array_column($array, 'first_name');

print_r($first_names);

?>

Output:

array

(

[0] => Peter

[1] => Ben

[2] => Joe

)

I hope it could help you...

#PHP