【发布时间】:2021-01-09 20:12:23
【问题描述】:
我正在尝试扩展一些工作代码,但不知道该怎么做。 基本上,信息可以在信息或其他标题下。 但我不关心这种分裂,我只想为他们所有人一起做一个 foreach。
基本上我目前为每个循环运行一个这样的:
foreach ($info_array['information'] as $item) {... do something }
是否有可能以某种方式说,对于每个 info_array 'information' & 'othertitle' as $item?
数组的结构如下:
information
random number
price
amount
total
random number
price
amount
total
othertitle
random number
price
amount
total
random number
price
amount
total
我试过了,但是没用:
foreach ($item_array['information'] as $item and $item_array['othertitle'] as $item)
【问题讨论】:
-
显示你想对循环中的项目做什么。
-
你试图通过这些双循环来实现什么?
-
我不想做双循环。我只想要“随机数”下的所有数据,我不在乎父母是“信息”还是“其他标题”。我只是不知道如何循环以一次获取“信息”和“其他标题”部分的所有价格/金额/总计
-
作为
othertitle跟随information两个循环 - 一个接一个 - 就足够了。 -
@u_mulder 所以最好的办法不是把它结合起来吗?但只是一个接一个地跑? (所以每个循环 2 个?)(我确实想到了这一点,但认为/希望有一个更优雅的解决方案 XD)