
在 php 中,可以通过数据库查询获取到这样的数据对象:
object(think\collection)#117 (1) {
["items":protected] => array(10) {
[0] => array(5) {
["id"] => int(2)
["post_id"] => int(7)
["category_id"] => int(9)
["list_order"] => float(10000)
["status"] => int(1)
}
...
}
}要将此对象转换为数组,可以使用 toarray 方法:
$data->toarray();
这样就能得到一个标准的 php 数组:
array(10) {
[0] => array(5) {
["id"] => int(2)
["post_id"] => int(7)
["category_id"] => int(9)
["list_order"] => float(10000)
["status"] => int(1)
}
...
}以上就是PHP中ThinkPHP Collection对象如何转换为标准数组?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号