DEV Community 👩‍💻👨‍💻

Mehedi Hasan Sagor for freecoder

Posted on

How can make an array from the values of another array's key?

Today what you are going to learn:
If you are working on PHP or other PHP framework and you want to create array of another array value. now you can see on following lesson how can you make array form another multidimensional array key's.

For lesson you have array like:

 $multi = array(

  ['1'] => array('id'=>1,'name'=>'hardik'),

  ['2'] => array('id'=>1,'name'=>'vimal'),

  ['3'] => array('id'=>1,'name'=>'harshad'),

)
Enter fullscreen mode Exit fullscreen mode

but if you want to this multi-dimensional array just like this way:

$test = array('hardik','vimal','harshad');
Enter fullscreen mode Exit fullscreen mode

so, we can make this type of array from multi-dimensional array using array_column() funtion.

you can use this function easy as under.

$result = array_column($multi, 'name');

Try this..........

Read More

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.