如何显示多维数组
我有一个与此类似的数组:
$suppliers = array(
'Utility Warehouse' => array('Gas' => array(0,0), 'Electricty' => array(0,0)),
'British Gas' => array('Gas' => array(93,124), 'Electricty' => array(93,124)),
'Eon' => array('Gas' => array(93,124), 'Electricty' => array(93,124))
);
如何显示如下信息?
Utility Warehouse
Gas: 0-0 Electricity 0-0
British Gas
Gas: 93-134 Electricity: 93-134
Eon
Gas: 93-124 Electricity: 93-134
您可以看到显示的数据与数组中的数据如何对应。我已经尝试过:
foreach($suppliers as $a){
echo $a[0];
}
但这没有任何作用。
I have this array similar to this:
$suppliers = array(
'Utility Warehouse' => array('Gas' => array(0,0), 'Electricty' => array(0,0)),
'British Gas' => array('Gas' => array(93,124), 'Electricty' => array(93,124)),
'Eon' => array('Gas' => array(93,124), 'Electricty' => array(93,124))
);
How can I display the information as follows?
Utility Warehouse
Gas: 0-0 Electricity 0-0
British Gas
Gas: 93-134 Electricity: 93-134
Eon
Gas: 93-124 Electricity: 93-134
You can see how the displayed data corresponds to the data in the array. I've tried this:
foreach($suppliers as $a){
echo $a[0];
}
But this does nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以尝试:
you can try:
下面是实现您想要的代码,但我建议您多温习一下您的 PHP 技能,因为这是一项微不足道的任务。
The code to achieve what you want would be following, but i suggest you brush up on your PHP skills a bit more, as this is a trivial task.
这是一个可以使用的简单递归函数。我找到了它并出于演示目的对其进行了修改。原始出处在评论里。
Here is a simple recursive function one can use. I found it and modified it for presentation purposes. The original source is in the comments.