dtwzwmv87399 2014-10-29 14:40
浏览 32

访问php数组内部[关闭]

I have a array print like this:

array(2) {
  ["systems"]=>
  array(5) {
    [1]=>
    string(1) "1111"
    [2]=>
    string(1) "2222"
    [3]=>
    string(1) "3333"
    [4]=>
    string(1) "4444"
    [5]=>
    string(1) "5555"
  }
  ["test"]=>
  string(2) "on"
}

Now , i want to access to every every inner value with using foreach or any code that will work with that code.

I mean for example, I want to echo Out something like this :

System "1" has "1111" value.
System "2" has "2222" value.
System "3" has "3333" value.
System "4" has "4444" value.
System "5" has "5555" value.

How can i have that output code ?

  • 写回答

3条回答 默认 最新

  • dpwjx32578146 2014-10-29 14:43
    关注

    Try this:

    $array = array(
        'systems' => array(
            1 => 1111,
            2 => 2222,
            3 => 3333,
            4 => 4444,
            5 => 5555
        ),
        'test' => 'on'
    );
    
    foreach ($array['systems'] as $key => $value) {
        echo 'System "' . $key . '" has "' . $value . '" value.'."<br />
    ";
    }
    

    if your name of your variable is $array.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计