我正在尝试从多维数组中输出分组数据。考虑最高级别的数组键“组”,然后在组内是单独的搜索行。
例如$group[ 0 ][ 1 ]
将是“第 1 组,第 1 行”。
我想显示每个组中的所有行,然后通过插入 ' <hr />
' 标记来表示该组已更改。目前第一组正确显示,然后显示 hr 标签,但第二组结果不显示。我的循环内循环方法错误吗?是否可以使用这样的多维数组?谢谢!!
我的数组如下所示:
Array
(
[0] => Array
(
[0] => stdClass Object
(
[name] => testing
[searchID] => 131
[lineID] => 190
[searchString] => 1
)
[1] => stdClass Object
(
[name] => testing
[searchID] => 131
[lineID] => 191
[searchString] => 2
)
[2] => stdClass Object
(
[name] => testing
[searchID] => 131
[lineID] => 192
[searchString] => 3
)
[3] => stdClass Object
(
[name] => testing
[searchID] => 131
[lineID] => 193
[searchString] => 4
)
)
[1] => Array
(
[4] => stdClass Object
(
[name] => test2
[searchID] => 132
[lineID] => 199
[searchString] => 1
)
[5] => stdClass Object
(
[name] => test2
[searchID] => 132
[lineID] => 200
[searchString] => 2
)
)
)
我的代码如下所示:
$x = 0;
$y = 0;
while( $x < count( $groups ) )
{
while( $y < count( $groups[ $x ] ) )
{
//display each single search string
echo $groups[ $x ][ $y ]->searchString.'<br>';
$y++;
}
echo '<hr>';
$x++;
}