dongmaoxi0477 2012-09-18 21:25
浏览 15
已采纳

PHP中的锯齿状边缘阵列

I want to store some data in (I guess a semi-2, semi-3d array) in PHP (5.3) What I need to do is store data about each floor like this:

Floor    Num of Spots    Handicap          Motorcyle        Other
1         100            array(15,16,17)    array (47,62)   array (99,100)
2         100            array(15,16,17)    array (47,62)   array (99,100)
and on

The problem is, is if the Handicap+Motorcyle+Other were ints, I could just store the data in a 2d array. However, they aren't. So I was thinking I could make something almost like a 3D array, with the first two columns only being in 2D.

The other thought I had was making a 2D array and for columns 3,4, and 5 instead of saving as

array(15,16)
//save like
1516

And then split at two digits (1 digit array numbers would be prefaced with a 0). However, I am wondering about the limit of the length of a string, because if I decide to move to a 3 digit length number in the array, like array(100, 104), and I need to store alot of numbers, I am thinking I am going to quickly exceed the max.

Edit 1 I like Omar's answer alot, but I'm not sure as to how to pull the data out.

  • 写回答

4条回答 默认 最新

  • duanen19871021 2012-09-18 21:37
    关注

    While you could store them as ?D array, there is another approach you might want to consider :

    $stuff = array (
      'floor1' => 
      array (
        'NumSpots' => 100,
        'handicap' => array (15,16,17),    
        'motorcycle' => array (47, 62),
        'other' =>  array (99, 100),
        ),
      ),
      'floor2' => 
        'NumSpots' => 100,
        'handicap' => array (15,16,17),    
        'motorcycle' => array (47, 62),
        'other' => array (99, 100),
        ),
      )
    )
    

    That way, you can access things through mroe meaningful names like

    $stuff['floor1']['motorcycle'][2]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?