dopii22884 2015-11-23 04:38
浏览 43
已采纳

按顺序在数组内部回显数组

I have this some arrays that look like this,

    $array = Array(
    'Homer' => Array
    (
        'id' => 222,
        'size' => 12

    ),
    'Bart' => Array
    (
        'id' => 333,
        'size' => 3
    )
);

I would like to echo Homer: id is 222, size is 12

then in the next line echo Bart: id is 333, size is 3 using a foreach loop as key and values.

So i basically want to echo all the Simpsons character names which have their id and size next their names.

I tired this but it printed homer too many times and it even used Bart's id and size at one point.

    foreach( $array as $billdate => $date) { 
foreach( $date as $k => $v) {         
    echo $billdate; // Prints Homer and bart
    foreach($array as $innerArray){

foreach($innerArray as $key => $value){
echo "[". $key ."][". $value ."] <br/>";
}}
    }            
} 

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dsh77114 2015-11-23 04:50
    关注

    you can try like this:

    foreach( $array as $billdate => $date) { 
      echo $billdate.': id is '.$date['id'].', size is '.$date['size'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接