我正在尝试制作迷你商店。
如何在阵列中添加一个键,两个值?
我试过这个:
array( "My Item" => "images/photo.jpg" => "9,99", "T-Shirt" => "images/tshirt.jpg" => "19,99");
答案 0 :(得分:3)
像这样:
array(
"My Item" => array("images/photo.jpg", "9,99"),
"T-Shirt" => array("images/tshirt.jpg", "19,99")
);
答案 1 :(得分:2)
由于PHP 5.4的语法很短:
$articles = [
'art1' => ['images/photo.jpg', 9.99],
'art2' => ['images/tshirt.jpg', 19.99]
];
了解详情:http://php.net/manual/en/language.types.array.php
一般而言:
答案 2 :(得分:0)
$array = array();
$array[] = array('1st', '1.1');
$array[] = array('2nd', '1.2');
$array[] = array('3rd', '1.3');