$bb=Array( [0] => 12 [1 => 1 [2] => 7 [3] => 10)
问题描述:将数组$aa里的数据进行处理。逗号后面的数重新组成新的数组 $bb。
代码如下:
$a=array("4,12","3,1","2,7","1,10");
print_r($a);
echo "<br/>";
foreach ($a as $key => $value) {
$b=explode(",", $value);
$c.=$b[1].",";
}
$d=array_filter(explode(",",$c));
print_r($d);
这里用到了两个php自带的函数:explode() 字符串转为数组 array_filter() 对数组去重操作。
问题描述:将数组$aa里的数据进行处理。逗号前面的数作为下标key,后面的数作为值value 组成新的数组 $cc。
$aa=Array( [0] => 4,12 [1] => 3,1 [2] => 2,7 [3] => 1,10)
$cc=Array( [4] => 12 [3] => 1 [2] => 7 [1] => 10)
代码如下:
$a=array("4,12","3,1","2,7","1,10");
print_r($a);
echo "<br/>";
$c=array();
foreach ($a as $key => $value) {
$b=explode(",", $value);
$d=$b[0];
$c[$d]=$b[1];
}
print_r($c);