PHP : echo 多维数组
PHP : echo Multidimensional Array
我有一个这样的数组输出:
Array
(
[2015-01-23] => Array
(
[0] => Array
(
[orgdate] => 2015-01-23
[origin] => india
)
[1] => Array
(
[orgdate] => 2015-01-23
[origin] => us
)
[2] => Array
(
[orgdate] => 2015-01-23
[origin] => england
)
[3] => Array
(
[orgdate] => 2015-01-23
[origin] => india2
)
[4] => Array
(
[orgdate] => 2015-01-23
[origin] => uae
)
[5] => Array
(
[orgdate] => 2015-01-23
[origin] => africa
)
[6] => Array
(
[orgdate] => 2015-01-23
[origin] => china
)
[7] => Array
(
[orgdate] => 2015-01-23
[origin] => hongkong
)
[8] => Array
(
[orgdate] => 2015-01-23
[origin] => africa2
)
[9] => Array
(
[orgdate] => 2015-01-23
[origin] => africa3
)
[10] => Array
(
[orgdate] => 2015-01-23
[origin] => africa4
)
[11] => Array
(
[orgdate] => 2015-01-23
[origin] => africa5
)
)
[2015-01-14] => Array
(
[0] => Array
(
[orgdate] => 2015-01-14
[origin] => japan1
)
[1] => Array
(
[orgdate] => 2015-01-14
[origin] => japan2
)
[2] => Array
(
[orgdate] => 2015-01-14
[origin] => japan3
)
[3] => Array
(
[orgdate] => 2015-01-14
[origin] => japan4
)
)
[2015-01-13] => Array
(
[0] => Array
(
[orgdate] => 2015-01-13
[origin] => russia
)
)
)
现在我想显示 2015-01-23 、 2015-01-14 、 2015-01-13 然后每个内部内容
origin: india
origin: usa
origin: england , etc....
我如何做到这一点。?我已经尝试过 this 之类的递归函数,但这找不到解决方案
任何帮助将不胜感激
你不需要递归,因为你的数组是平面的(只有 1 深)
我不确定你想要什么但是:
foreach($array as $key=>$subarray)
{
echo $key;
foreach($array[$key] as $subarray)
{
echo "origin".$subarray["origin"];
}
}
这应该有效。
如果您只想查看调试,请使用 var_dump($array);
试试这个:
foreach($array as $innerArray){
foreach($innerArray as $result){
echo "origin: "." ".$result['orgdate']." ".$result['origin'];
}
}
我有一个这样的数组输出:
Array
(
[2015-01-23] => Array
(
[0] => Array
(
[orgdate] => 2015-01-23
[origin] => india
)
[1] => Array
(
[orgdate] => 2015-01-23
[origin] => us
)
[2] => Array
(
[orgdate] => 2015-01-23
[origin] => england
)
[3] => Array
(
[orgdate] => 2015-01-23
[origin] => india2
)
[4] => Array
(
[orgdate] => 2015-01-23
[origin] => uae
)
[5] => Array
(
[orgdate] => 2015-01-23
[origin] => africa
)
[6] => Array
(
[orgdate] => 2015-01-23
[origin] => china
)
[7] => Array
(
[orgdate] => 2015-01-23
[origin] => hongkong
)
[8] => Array
(
[orgdate] => 2015-01-23
[origin] => africa2
)
[9] => Array
(
[orgdate] => 2015-01-23
[origin] => africa3
)
[10] => Array
(
[orgdate] => 2015-01-23
[origin] => africa4
)
[11] => Array
(
[orgdate] => 2015-01-23
[origin] => africa5
)
)
[2015-01-14] => Array
(
[0] => Array
(
[orgdate] => 2015-01-14
[origin] => japan1
)
[1] => Array
(
[orgdate] => 2015-01-14
[origin] => japan2
)
[2] => Array
(
[orgdate] => 2015-01-14
[origin] => japan3
)
[3] => Array
(
[orgdate] => 2015-01-14
[origin] => japan4
)
)
[2015-01-13] => Array
(
[0] => Array
(
[orgdate] => 2015-01-13
[origin] => russia
)
)
)
现在我想显示 2015-01-23 、 2015-01-14 、 2015-01-13 然后每个内部内容
origin: india
origin: usa
origin: england , etc....
我如何做到这一点。?我已经尝试过 this 之类的递归函数,但这找不到解决方案
任何帮助将不胜感激
你不需要递归,因为你的数组是平面的(只有 1 深)
我不确定你想要什么但是:
foreach($array as $key=>$subarray)
{
echo $key;
foreach($array[$key] as $subarray)
{
echo "origin".$subarray["origin"];
}
}
这应该有效。 如果您只想查看调试,请使用 var_dump($array);
试试这个:
foreach($array as $innerArray){
foreach($innerArray as $result){
echo "origin: "." ".$result['orgdate']." ".$result['origin'];
}
}