Convert an associative array to a simple array of its values in php

孤街浪徒 提交于 2019-11-26 08:19:49

问题


I would like to convert the array:

Array ( 
[category] => category 
[post_tag] => post_tag 
[nav_menu] => nav_menu 
[link_category] => link_category 
[post_format] => post_format 
)

to

array(category, post_tag, nav_menu, link_category, post_format)

I tried

$myarray = \'array(\'. implode(\', \',get_taxonomies(\'\',\'names\')) .\')\';

which echos out:

array(category, post_tag, nav_menu, link_category, post_format)

So I can do

echo $myarray;
echo \'array(category, post_tag, nav_menu, link_category, post_format)\';

and it prints the exact same thing.

...but I can\'t use $myarray in a function in place of the manually entered array because the function doesn\'t see it as array or something.

What am I missing here?


回答1:


simply use array_values function:

$array = array_values($array);



回答2:


You should use the array_values() function.



来源:https://stackoverflow.com/questions/15191903/convert-an-associative-array-to-a-simple-array-of-its-values-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!