在php中遍历一个数组,并将其存入一个一维数组中,
数组如下:$result=Array(0=>Array(days=>20131217),1=>Array(days=>20131218),2=>Array(days=>2...
数组如下:
$result=Array (0 => Array ( days => 20131217 ) ,
1 => Array ( days => 20131218 ) ,
2 => Array ( days => 20131219 ) ,
3 => Array ( days => 20131220 ) ,
4 => Array ( days => 20131221 ) ,
5 => Array ( days => 20131222 ) ,
6 => Array ( days => 20131223 ) ,
);
鄙人使用的方法如下:
$arr=array();
for($i=0;$i<count($result);$i++){
$arr= $result[$i];
echo $i." ";
echo $arr."<br/>";
} 展开
$result=Array (0 => Array ( days => 20131217 ) ,
1 => Array ( days => 20131218 ) ,
2 => Array ( days => 20131219 ) ,
3 => Array ( days => 20131220 ) ,
4 => Array ( days => 20131221 ) ,
5 => Array ( days => 20131222 ) ,
6 => Array ( days => 20131223 ) ,
);
鄙人使用的方法如下:
$arr=array();
for($i=0;$i<count($result);$i++){
$arr= $result[$i];
echo $i." ";
echo $arr."<br/>";
} 展开
展开全部
$result=Array (0 => Array ( 'days' => 20131217 ) ,
1 => Array ( 'days' => 20131218 ) ,
2 => Array ( 'days' => 20131219 ) ,
3 => Array ( 'days' => 20131220 ) ,
4 => Array ( 'days' => 20131221 ) ,
5 => Array ( 'days' => 20131222 ) ,
6 => Array ( 'days' => 20131223 ) ,
);
foreach($result as $key=>$value){
$newarr[]=$value['days']; //放入一维数组newarr
};
print_r($newarr);
//Array ( [0] => 20131217 [1] => 20131218 [2] => 20131219 [3] => 20131220 [4] => 20131221 [5] => 20131222 [6] => 20131223 )
1 => Array ( 'days' => 20131218 ) ,
2 => Array ( 'days' => 20131219 ) ,
3 => Array ( 'days' => 20131220 ) ,
4 => Array ( 'days' => 20131221 ) ,
5 => Array ( 'days' => 20131222 ) ,
6 => Array ( 'days' => 20131223 ) ,
);
foreach($result as $key=>$value){
$newarr[]=$value['days']; //放入一维数组newarr
};
print_r($newarr);
//Array ( [0] => 20131217 [1] => 20131218 [2] => 20131219 [3] => 20131220 [4] => 20131221 [5] => 20131222 [6] => 20131223 )
展开全部
$days = array();
for($i=0;$i<count($result);$i++){
$arr = $result[$i];
echo $i." ";
echo $arr['days']."<br>";
$days[] = $arr['days'];
}
print_r($days);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$result=Array (
0 => Array ( 'days' => 20131217) ,
1 => Array ( 'days' => 20131218 ) ,
2 => Array ( 'days' => 20131219 ) ,
3 => Array ( 'days' => 20131220 ) ,
4 => Array ( 'days' => 20131221 ) ,
5 => Array ( 'days' => 20131222 ) ,
6 => Array ( 'days' => 20131223 ) ,
);
foreach ($result as $a){
foreach ($a as $b){
$c[]=$b;
}
}
print_r($c);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
function arrayChange($array){static $arr2=array();
foreach($array as $v){
if(is_array($v)){
arrayChange($v);
}else{
$arr2[]=$v;
}
}
$arr2=array_unique($arr2); //这条语句是去掉重复值的
return $arr2;
}
$arr=arrayChange($result);
var_dump($arr);
?>
function arrayChange($array){static $arr2=array();
foreach($array as $v){
if(is_array($v)){
arrayChange($v);
}else{
$arr2[]=$v;
}
}
$arr2=array_unique($arr2); //这条语句是去掉重复值的
return $arr2;
}
$arr=arrayChange($result);
var_dump($arr);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询