I have an array with following format.
Array
(
[0] => Array
(
[keyword] => thumbnail_follow
[content] => width
)
[1] => Array
(
[keyword] => thumbnail_resize
[content] => yes
)
)
My desire output is following
Array
(
[thumbnail_follow] => width
[thumbnail_resize] => yes
)
What I have tried so far?
array_shift() but this remove duplicate keys and output become
Array
(
[keyword] => thumbnail_follow
[content] => width
)
array_column I am able to get only single type of values. For example array_column($array, 'keyword')
Array
(
[0] => thumbnail_follow
[1] => thumbnail_resize
)
Using array_column and loop, I can get desire output but there must be some more efficient way to do it but I am known from this
Can you please help me guys?
Using array_column 's third parameter index_key you can do it. Please look at 2nd example of function.
Use it like this
print_r( array_column($array, 'content', 'keyword') );
You should get your desire output by this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With