I have this comma delimited list 0,0,0,0,5,0,7,8,9,10
and i would like to get rid of the number zero represented as a number on its own right and not the zero in 10
.
The list is represented in the variable $str
and this is the code i am trying to remove the zero with.
$str;
$myArray = explode(',', $str);
if (($key = array_search('0', $myArray)) !== false) {
unset($myArray[$key]);
}
print_r($myArray);
$csv = implode(', ', $myArray);
echo $csv;
but this gives 0, 0, 0, 5, 0, 7, 8, 9, 10
This code does not do the job as i would have liked.What can i do to get rid of the zeros?.