【发布时间】:2011-04-26 22:56:01
【问题描述】:
我有一个这样的 foreach 循环:
$test_array = array(1, 2, 3, 4, 5);
foreach($categories as $category)
{
echo $category; // outputs cat one cat two cat three cat four cat five etc
echo $test_array; // outputs Array Array Array Array Array
}
这显示得很好。
但我也想输出 test_array 数组,但是当我这样做时,它会显示“Array Array Array Array Array Array”以及我的类别:(
如何让 test_array 也显示在我的 foreach 循环中?
【问题讨论】:
-
你的意思是每次显示所有元素,还是每个类别一个?
-
你能发布你使用的输出'Array Array etc'的代码吗?
-
@cHao 同时显示类别数组和 test_array
-
@Keith:这并不能真正回答问题。你想要“猫一 1 2 3 4 5 猫二 1 2 3 4 5”或“猫一猫二.... 1 2 3 4 5”?
-
@cHao: stackoverflow.com/questions/5797436/… 这样,这似乎工作得很好!