Search code snippets, questions, articles...

Get values array by key name using array_column() PHP

You can get an array of values by key name from an associative array using the array_column() function PHP
<?php
    $employees = array(
        array(
            'emp_name' => 'Rick Grimes',
            'designation' => 'developer'
        ),
        array(
            'emp_name' => 'John Wick',
            'designation' => 'manager'
        )
    );

    $designations = array_column($employees, 'designation');
    print_r($designations);
?>

Search Index Data (The code snippet can also be found with below search text)

array_column() PHP
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet