使用嵌套标准类对象按特定值对多维数组进行分组
在上一篇文章中,有一个关于分组多维数组的非常有用的答案。我的问题与我的初始数组有一个嵌套标准类对象的问题类似。我的数组看起来像这样:
Array
(
[0] => stdClass Object
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[1] => stdClass Object
(
[InstallationAddress2] => Santa Rosa, CA 90230
[LineitemmasterDescription] => Berries
[Workorder_id] => W008022342
)
[2] => stdClass Object
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
)
就像上一篇文章一样,我希望得到类似的东西
Array
(
[1] => Array
[0] => Array
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[1] => Array
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[2] => Array
(
[InstallationAddress2] => Santa Rosa, CA 90230
[LineitemmasterDescription] => Berries
[Workorder_id] => W008022342
)
)
我绊倒的是标准类对象,它拒绝转换为数组。
In a previous post there was a very helpful answer on grouping multidimensional arrays. My issue is similar with the twist that my initial array has a nested standard class object. My array looks like this:
Array
(
[0] => stdClass Object
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[1] => stdClass Object
(
[InstallationAddress2] => Santa Rosa, CA 90230
[LineitemmasterDescription] => Berries
[Workorder_id] => W008022342
)
[2] => stdClass Object
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
)
Like the previous post I'm hoping to get something like
Array
(
[1] => Array
[0] => Array
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[1] => Array
(
[InstallationAddress2] => LAKEWOOD, CA 90000
[LineitemmasterDescription] => Apples
[Workorder_id] => W008052094
)
[2] => Array
(
[InstallationAddress2] => Santa Rosa, CA 90230
[LineitemmasterDescription] => Berries
[Workorder_id] => W008022342
)
)
The thing I'm stumbling over is the standard class object which refuses to be cast into an array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过循环遍历数组来对每个 std 对象执行 (array) 类型转换。
然后您可以应用您的分组逻辑。
请参阅类型转换示例:http://codepad.org/uVuBzBm8
do (array) type cast of each of the std objects by looping through your array.
Then you can apply your grouping logic.
See typecasting example : http://codepad.org/uVuBzBm8