Dev*_*Hub 3 php arrays multidimensional-array
我有以下格式的数组。
Array
(
[0] => Array
(
[keyword] => thumbnail_follow
[content] => width
)
[1] => Array
(
[keyword] => thumbnail_resize
[content] => yes
)
)
Run Code Online (Sandbox Code Playgroud)
我的愿望输出如下
Array
(
[thumbnail_follow] => width
[thumbnail_resize] => yes
)
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过什么?
array_shift() 但这会删除重复的键并输出
Array
(
[keyword] => thumbnail_follow
[content] => width
)
Run Code Online (Sandbox Code Playgroud)array_column我只能获得单一类型的值。例如array_column($array, 'keyword')
Array
(
[0] => thumbnail_follow
[1] => thumbnail_resize
)
Run Code Online (Sandbox Code Playgroud)使用array_column和loop,我可以获得期望的输出,但是必须有一些更有效的方法来实现,但是据我所知
你能帮我吗?
使用array_column 的第三个参数,index_key您可以做到。请看功能的第二个例子。
这样使用
print_r( array_column($array, 'content', 'keyword') );
Run Code Online (Sandbox Code Playgroud)
您应该由此获得期望的输出。