我试图在这里解析。这是我的数组的内容
Array ( [61] => [128] => [158] => [224] => [281] => AGAS, [282] => JAMES [283] => JAY [285] => [329] => [330] => 03/02/2015 [331] => 6:46 [332] => am [333] => 5:42 [334] => pm [433] => APOLLOL, [434] => KARMIN [436] => [480] => [481] => 03/01/2015 [598] => )
我可以看到我的数组中有空值,我尝试过这段代码:
$final2=array_filter($final);
$trimmed_array=array_map('trim',$final2);
但是有些空值不会被删除,我怎样才能使我的数组像这样:
Array ([1] => AGAS, [2] => JAMES [3] => JAY [4] => [5] => 03/02/2015 [6] => 6:46 [7] => am [8] => 5:42 [9] => pm [10] => APOLLOL, [11] => KARMIN [12] => 03/01/2015)
答案 0 :(得分:0)
请看下面给出的功能。希望这会帮助你。此函数将所有空值转换为空白(“”)。
function array_remove_empty($Yourarray) {
foreach ($Yourarray as $key => $value) {
if (is_array($value)) {
$Yourarray[$key] = array_remove_empty($Yourarray[$key]);
}
if (empty($Yourarray[$key])) {
$Yourarray[$key] = "";
}
}
return $Yourarray;
}
答案 1 :(得分:0)
$inputArray = array (
'61'=> '',
'128' => '',
'158' => '',
'224' => '',
'281' => 'AGAS',
'282' => 'JAMES' ,
'283' => 'JAY' ,
'285' =>'',
'329' => '',
'330' => '03/02/2015',
'331' => '6:46' ,
'332' => 'am' ,
'333' => '5:42',
'334' =>'pm' ,
'433' => 'APOLLOL',
'434' =>'KARMIN' ,
'436' =>'' ,
'480' => '',
'481' => '03/01/2015' ,
'598' => '',
);
$reqResult = array (
'1' => 'AGAS',
'2' => 'JAMES',
'3' => 'JAY',
'4' =>'',
'5' => '03/02/2015',
'6' => '6:46',
'7' => 'am' ,
'8' => '5:42' ,
'9' => 'pm' ,
'10' => 'APOLLOL',
'11'=> 'KARMIN' ,
'12' => '03/01/2015',
);
我假设reqResult中的偏移4是一个错误。
$myResult = array();
$i=1;
foreach($inputArray as $key => $value){
if($value!=''){
$myResult[$i]= $value;
$i++;
}
}
print_r($myResult);