I need to clean the following PHP array and remove all the empty variables. The array is the made from the string which was copied from a third part software and contains lots of line breaks.
The ways in which I tried and failed are given below.
The array:
Array (
[0] =>
[1] => 1.BOB/SMITH RANI MRS
[2] => 2.JON/SMITH MSTR(CHD/01NOV01)
[3] =>
[4] => 3.BOB/JONES MSTR(CHD/01JUN01)
[5] => 4 EK 004 U 26JUL 6*LHRDXB HK3 2040 0630 27JUL E EK/GAQNL2
[6] => 5 EK 584 U 27JUL 7*DXBDAC HK3 1315 1955 27JUL E EK/GAQNL2
[7] => 6 EK 583 U 09SEP 2*DACDXB HK3 1015 1305 09SEP E EK/GAQNL2
[8] => 7 EK 005 U 09SEP 2*DXBLHR HK3 1545 2015 09SEP E EK/GAQNL2 )
function that I tried and failed:
public static function filter_array_empty_value($arr){
foreach($arr as $k=>$v){
$v = str_replace("\n","",$v);
$v = str_replace(" ","",$v);
$v = trim($v);
for($i=1;$i<=50;$i++){
$v = str_replace("\n","",$v);
$v = str_replace(" ","",$v);
}
if($v == " " || $v == NULL || empty($v) || strlen($v)<1){
unset($arr[$k]);
}
}
return $arr;
}
Note: The array[0] has string length of 4 even after trimming.
Help is appreciated.