问题描述
有没有一种简单的方法来遍历这个结构在PHP关联数组:
Is there an easy way to iterate over an associative array of this structure in PHP:
阵列 $搜索
有编号的指数,与4和5之间的关联部件。所以,我不仅需要遍历 $搜索[0]
到 $搜索[N]
,也 $搜索[0] [PART0]
到 $搜索[N] [PARTN]
。难的是,不同的指数具有部分不同的数字(有些人可能会丢失一个或两个)。
The array $searches
has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate over $searches[0]
through $searches[n]
, but also $searches[0]["part0"]
through $searches[n]["partn"]
. The hard part is that different indexes have different numbers of parts (some might be missing one or two).
这在某种程度上是很好,整洁,可以理解这样的想法?
Thoughts on doing this in a way that's nice, neat, and understandable?
推荐答案
我不知道我理解的问题。你知道循环?为什么不干脆窝呢?
I'm not sure I understand the problem. Do you know the foreach
loop? Why not simply nest it?
foreach ($array as $i => $values) {
print "$i {\n";
foreach ($values as $key => $value) {
print " $key => $value\n";
}
print "}\n";
}
这篇关于遍历在PHP中一个复杂的关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!