Laravel 输出:
Array
(
[0] = stdClass Object
(
[ID] = 5
)
[1] = stdClass Object
(
[ID] = 4
)
)
我想将其转换为普通数组。只想删除那个 stdClass 对象
。我也尝试使用 ->toArray();
但我收到错误:
Call to a member function toArray() on a non-object.
我该如何解决这个问题?
功能已在 http://www.srihost.com 上实现
最佳答案
foreach($yourArrayName as $object)
{
$arrays[] = $object->toArray();
}
// Dump array with object-arrays
dd($arrays);
或者当 toArray()
因为它是一个标准类而失败时
foreach($yourArrayName as $object)
{
$arrays[] = (array) $object;
}
// Dump array with object-arrays
dd($arrays);
不工作?也许你可以在这里找到答案:
关于php - 将 laravel 对象转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26174267/