doucuan5365 2014-01-18 21:30
浏览 47
已采纳

如何使用Multidimensional Arrays PHP

I want to use multi dimensional arrays in a project I am doing, and I cannot figure out how to code it.

I have 3 things I want to store, a single string called "attribute name", another single string called "attribute type" and a collection of strings called "attributeOptions".

So if I had the data, attribute name="Brand", attribute type="sports", attribute options="nike|addidas|puma", I would want to be able to input and extract all of this information at once using a loop.

Am I thinking about multidimensional arrays the wrong way or how would I go about coding this in PHP?

  • 写回答

1条回答 默认 最新

  • dongpu5600 2014-01-18 21:34
    关注

    Like this

    $md = array (
        "name"  => "a",
        "attribute" => "type",
        "options"  => array("Nike", "etc0", "etc1") // Array
    );
    
    
    
    $array['name'] = 'a';
    $array['attribute'] = 'type';
    $array['options'][0] = 'Nike';
    $array['options'][1] = 'Nike or Other';
    $array['options'][2] = 'Nike or Other Other';
    

    Or you could do

    $array['name'] = 'a';
    $array['attribute'] = 'type';
    $array['options']['optionOne'] = 'Nike';
    $array['options']['optionTwo'] = 'Nike or Other';
    $array['options']['optionThree'] = 'Nike or Other Other';
    

    See?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大