douzheyo2617 2016-08-05 09:12
浏览 36

如何在php中打印多级数组索引

I have the following array:

$array=array("string",array(1,2,3),true,"php");

and I want to print indexes like:

0=>string


1.0=>1


1.1=>2


1.2=>3


2=>true


3=>php
  • 写回答

6条回答 默认 最新

  • douqiao5314 2016-08-05 09:18
    关注
    <?php
    
    $array=array("string",array(1,2,3),true,"php");
    
    foreach($array as $key=>$value)
    {
      if(is_array($value))
      {
        foreach($value as $childkey=>$childvalue)
        {
          echo $key . "." . $childkey . "=>" . $childvalue . "
    ";
        }
      }
      elseif(is_bool($value))
      {
        echo $key . "=>" . ($value ? "true" : "false") . "
    ";
      }
      else
      {
        echo $key . "=>" . $value . "
    ";
      }
    }
    

    Output:

    0=>string
    1.0=>1
    1.1=>2
    1.2=>3
    2=>true
    3=>php
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器