PHP数组的操作(新建,取下标,内容)

新建数组方法之一:

$cs2 = array("100"=>"全部","101"=>"云浮","102"=>"肇庆","103"=>"广州");
print_r($cs2);
print_r(array_keys($cs2));

输出:

Array ( [100] => 全部 [101] => 云浮 [102] => 肇庆 [103] => 广州 ) Array ( [0] => 100 [1] => 101 [2] => 102 [3] => 103 )

也可以用:
$cs2 = array("全部","云浮","肇庆","广州");

输出: Array ( [0] =>全部 [1] =>云浮 [2] => 肇庆 [3] => 广州 ) 
 
  

 对数组下标的操作: 
  
$arr=array();
$arr["aa"]["a"]="w";
$arr["bb"]["b"]="x";
$arr["cc"]["c"]="y";
$arr["dd"]["d"]="z";
print_r($arr);
echo "
"; foreach( array_keys($arr) as $k1 ) { foreach( array_keys($arr[$k1]) as $k2 ) { echo "key1:\"$k1\" key2:\"$k2\"
"; } }

输出结果:
Array ( [aa] => Array ( [a] => w ) [bb] => Array ( [b] => x ) [cc] => Array ( [c] => y ) [dd] => Array ( [d] => z ) ) 
key1:"aa" key2:"a"
key1:"bb" key2:"b"
key1:"cc" key2:"c"
key1:"dd" key2:"d"


转载请标明出处: http://blog.csdn.net/luckily01/article/details/7719498

 
  
 
 

你可能感兴趣的:(PHP开发)