php 二维数组赋值定义

2024-11-30 02:58:14
推荐回答(5个)
回答1:

多维数组定义、赋值参考如下:
$fruits = array ( "fruits" => array ( "a" => "orange",
"b" => "banana",
"c" => "apple"
),
"numbers" => array ( 1,
2,
3,
4,
5,
6
),
"holes" => array ( "first",
5 => "second",
"third"
)
);

// Some examples to address values in the array above
echo $fruits["holes"][5]; // prints "second"
echo $fruits["fruits"]["a"]; // prints "orange"
unset($fruits["holes"][0]); // remove "first"

// Create a new multi-dimensional array
$juices["apple"]["green"] = "good";
?>

回答2:

$arr = array(array('id'=>1, 'xuefei'=>"50万以下" ), array('id'=>2, 'xuefei'=>"51万~60万" ));

回答3:

$arr = array(
array('id'=>1,'xuefei'=>'50万以下'),
array('id'=>2,'xuefei'=>'51万~60万'),
array('id'=>3,'xuefei'=>'61万~70万'),
array('id'=>4,'xuefei'=>'71万~80万'),
array('id'=>5,'xuefei'=>'81万~90万'),
array('id'=>6,'xuefei'=>'90万以上'));

回答4:

$xuefei = array(array(id=>1,xuefei=>'50万以下'),array(id=>2,xuefei=>'50万~60万'),array(id=>3,xuefei=>'60万~70万'),array(id=>4,xuefei=>'70万~80万'),array(id=>5,xuefei=>'80万~90万'),array(id=>6,xuefei=>'90万以上'));

回答5:

示例:
$array = array();
$item = array();
$item['id'] = 1;
$item['xuefei'] = '50w';
$array[] = $item;

这三行
$item = array();
$item['id'] = 1;
$item['xuefei'] = '50w';

等效于 $item = array('id' => 1, 'xuefei' => '50w');

在php中,对于数组可以直接使用$array[]的方法在其尾部追加一个元素。例如
$array = array();
$array[] = 1;
结果为
Array (
0 => 1

)