脚本宝典收集整理的这篇文章主要介绍了php – 将对象转换为数组,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
任何帮助或指导将不胜感激.
我正在使用WP功能get_categories();
$category的完整内容是:
$category->term_id $category->name $category->slug $category->term_group $category->term_taxonomy_id $category->taxonomy $category->description $category->parent $category->count $category->cat_ID $category->category_count $category->category_description $category->cat_name $category->category_nicename $category->category_parent
$example = new StdClass(); $example->foo = 'bar'; var_dump((array) $example);
输出:
array(1) { ["foo"]=> string(3) "bar" }
但是这只会转换基础级别.如果你有嵌套对象,如
$example = new StdClass(); $example->foo = 'bar'; $example->bar = new StdClass(); $example->bar->blah = 'some value'; VAR_dump((array) $example);
然后只将基础对象强制转换为数组.
array(2) { ["foo"]=> string(3) "bar" ["bar"]=> object(stdClass)#2 (1) { ["blah"]=> string(10) "some value" } }
以上是脚本宝典为你收集整理的php – 将对象转换为数组全部内容,希望文章能够帮你解决php – 将对象转换为数组所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。