如何定义一个多维数组?

时间:2014-08-09 10:04:30

标签: php arrays

我想在数组中构造以下细节:

http://i59.tinypic.com/2ynmf83.png

我该怎么做?

$pokemon = array
(
    array(values...,values...),
    array(values...,values...),
    array(values...,values...);
);

我不认为上面的内容会对我有所帮助..因为我想命名甚至是行....... pokemon1,pokemon2 ..等等...

所以我可以在我的代码中有效地使用它!??我想知道如何将它构建成数组!

2 个答案:

答案 0 :(得分:1)

你的意思是:

$pokemon1 = "poke1";
$pokemon2 = "poke2";
$pokemon3 = "poke3";

$pokemon = array (  array($pokemon1, 'level' => "test", 'health' => "test"), 
                    array($pokemon2, 'level' => "test", 'health' => "test"), 
                    array($pokemon3, 'level' => "test", 'health' => "test")
                );


var_dump($pokemon);


array(3) {
  [0]=>
  array(3) {
    [0]=>
    string(5) "poke1"
    ["level"]=>
    string(4) "test"
    ["health"]=>
    string(4) "test"
  }
  [1]=>
  array(3) {
    [0]=>
    string(5) "poke2"
    ["level"]=>
    string(4) "test"
    ["health"]=>
    string(4) "test"
  }
  [2]=>
  array(3) {
    [0]=>
    string(5) "poke3"
    ["level"]=>
    string(4) "test"
    ["health"]=>
    string(4) "test"
  }
}

答案 1 :(得分:0)

$multiArray[] = array("Pokemon1", "level", "health");
$multiArray[] = array("Pokemon2", "level", "health");

看看;

http://php.net/manual/tr/language.types.array.php