dqj29136 2014-08-05 10:00
浏览 17
已采纳

声明多维数组最明显的是什么?

I have started to understand the 2D array and multi-dimensional array, some reference books mentioned it has different ways to declare them. Which methods will be declare the array more easier and easy to understand?

method 1:

      $pgmCode = array
            (
             "Item1"=>array("...","..."=>array("..."=>1)),
             ......
            )

Or method2:

      $A['ABC']['...'] = '3';
      $A['...']['...']['...'] = '2';

Furthermore, if I will build a database and calling the data as array store, which method will be preferred to use?

Thanks.

  • 写回答

2条回答 默认 最新

  • doubang9906 2014-08-05 10:18
    关注
    $pgmCode = array(
        "item1" = array(
            "subItem1" => true,
            "subItem2" => array("subSubItem1", "subSubItem2"),
        ),
        "item2" = array(
            "subItem1" => true,
            "subItem2" => array("subSubItem1", "subSubItem2"),
        ),
    );
    

    Watchout with mixed use of array and string item in an array, if you will do a in_array() on a mixed variable array it will always return true if you don't use the strict mode of the function.

    in your method 1

    in_array("something", $pgmCode['Item1']); //return true
    in_array("something", $pgmCode['Item1'], true); //return false
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!