Hello friends,
Here I am explaining that if you want to get all the values from a specific column from a multidimensional array then you can use a php predefined function which is "array_column()".
array_column returns the values from a single column in the input array.
Here is a example which will explain you clearly-
<?php
$userrecords = array(
array(
'id' => 1234,
'first_name' => 'John',
'last_name' => 'Cena',
),
array(
'id' => 3245,
'first_name' => 'Julia',
'last_name' => 'Robert',
),
array(
'id' => 5342,
'first_name' => 'James',
'last_name' => 'Bond',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Cena',
)
);
$first_names = array_column($userrecords, 'first_name');
print_r($first_names);
?>
Output:
Array
(
[0] => John
[1] => Julia
[2] => James
[3] => Peter
)
0 Comment(s)