如果出现foreach值,则添加一些数据
我得到:
foreach ($query as $sample) {
[..]
}
并且我需要更改它,因此如果所有带有
$sample['key'] == 1
的值都会被 foreach 循环,并且下一个循环将具有 $sample[ 'key'] == 0
,然后它会添加例如:
<tr><td colspan="4">All keys with $sample['key'] == 1 are after the loop, and I'm staring to loop with $sample['key'] == 0</td></tr>
但仅一次。
//编辑
试图解释更多:
首先:foreach
将循环这个:
foreach($query as $sample) {
*loop*
print_r($sample['key']) //1
*loop*
print_r($sample['key']) //1
...etc.
}
但是如果出现类似的内容:
foreach($query as $sample) {
*loop*
print_r($sample['key']) //1
*loop*
*adding some content, because next print value is 0!*
print_r($sample['key']) //0!!!!!!!
}
希望你现在明白了,我已经尽力解释了能。这很难描述,所以如果您有任何疑问,请随时在评论中提问。
I got:
foreach ($query as $sample) {
[..]
}
And I need it to be changed so if all values with
$sample['key'] == 1
Gonna be looped by the foreach and the next loop will have $sample['key'] == 0
, then it'll add for example something like:
<tr><td colspan="4">All keys with $sample['key'] == 1 are after the loop, and I'm staring to loop with $sample['key'] == 0</td></tr>
But only once.
//edited
Trying to explain more:
At first: foreach
will loop this:
foreach($query as $sample) {
*loop*
print_r($sample['key']) //1
*loop*
print_r($sample['key']) //1
...etc.
}
But if there'll be something like:
foreach($query as $sample) {
*loop*
print_r($sample['key']) //1
*loop*
*adding some content, because next print value is 0!*
print_r($sample['key']) //0!!!!!!!
}
Hope you understand it now, I've done my best to explain as best as I can. It's hard to describe, so if you have some questions, feel free to ask in the comments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我 100% 理解这个问题,但听起来几乎像
array_filter
可能会有一些帮助:否则你总是可以保留一个状态变量来查看何时进行切换:
不过,不可否认,我不知道100% 得到你想要的询问。
I'm not sure I 100% understand the question, but it sounds almost like
array_filter
may be of some help:Otherwise you could always keep a state variable to see when the switch was made:
Though, admittedly, I don't 100% get what you're asking.