使用 FOR 或 FOREACH 循环无限循环数组中的数据?
如果我可以循环这个水平数据数组,无论添加多少数据数组,有没有办法循环该垂直数据数组,无论添加多少数据?
// Expect Many arrays of data will be added
$array = [
[1,2,3,4,5],
[101,102,103,104,105],
[10,20,30,40,50],
[210,220,230,240, 250 => ['x','y','z'] ],
[100,200,300,400,500, ['a','b','c'] ],
];
// Loop the array data as added
// Loop Horizontal no matter how many arrays of data's will added
for ( $i=0; $i < count($array) ; $i++) {
echo "<pre>";
print_r($array[$i]);
echo "</pre>";
}
// How can I loop this array using FOR loop or FOREACH loop ?
// This will loop Vertical Expect that many arrays of data will added or appended on it .
[210,220,230,240, 250 => ['x','y','z'] ],
[100,200,300,400,500, ['a','b','c'] ]
结果:数组转换为字符串
- 提前致谢
If I can loop this Horizontal array of data no matter how many arrays of data will add, Is there a way to loop that Vertical array of data no matter how many data will be added?
// Expect Many arrays of data will be added
$array = [
[1,2,3,4,5],
[101,102,103,104,105],
[10,20,30,40,50],
[210,220,230,240, 250 => ['x','y','z'] ],
[100,200,300,400,500, ['a','b','c'] ],
];
// Loop the array data as added
// Loop Horizontal no matter how many arrays of data's will added
for ( $i=0; $i < count($array) ; $i++) {
echo "<pre>";
print_r($array[$i]);
echo "</pre>";
}
// How can I loop this array using FOR loop or FOREACH loop ?
// This will loop Vertical Expect that many arrays of data will added or appended on it .
[210,220,230,240, 250 => ['x','y','z'] ],
[100,200,300,400,500, ['a','b','c'] ]
Result: Array conversion to string
- Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望递归地循环遍历数组,当您在数组中找到数组时,您也可以循环遍历该数组,这是一种方法:
If you're looking to loop through an array recursively where when you find an array inside an array, you loop through that as well, here's a way to do that: