php 二维数组赋值定义
发布网友
发布时间:2022-04-06 01:26
我来回答
共5个回答
热心网友
时间:2022-04-06 02:56
*数组定义、赋值参考如下:
<?php
$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";
?>
热心网友
时间:2022-04-06 04:14
$arr = array(array('id'=>1, 'xuefei'=>"50万以下" ), array('id'=>2, 'xuefei'=>"51万~60万" ));
热心网友
时间:2022-04-06 05:48
$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万以上'));
热心网友
时间:2022-04-06 07:40
$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万以上'));
热心网友
时间:2022-04-06 09:48
示例:
$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
)