ItSolutionStuff.com

How can Make an Array from the Values of Another Array's Key Value?

By Hardik Savani • November 5, 2023
PHP

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 example how can you make array form another multidimensional array key's.

For example you have array like:

$multi = array(

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

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

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

)

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

$test = array('hardik','vimal','harshad');

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..........

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Convert Object to Array in Laravel?

Read Now →

How to Add JQuery Modal Popup in PHP?

Read Now →

How to Increase Upload File Size Limit PHP in Ubuntu?

Read Now →

How to Convert Array Values to Lowercase in PHP?

Read Now →

How to Convert Object into Array in PHP?

Read Now →

How to Remove Specific Element by Value from Array in PHP?

Read Now →

How to Get Maximum Key Value of Array in PHP?

Read Now →

How to Remove Empty Values from Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Count Number of Files in a Directory in PHP?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →

How to Merge Two Array with Same Keys without Loop in PHP?

Read Now →