I have an array.
If any array values within between becomes empty or null I want any after that empty value to be shifted within that empty array.
I used a foreach loop by unsetting an array but the problem is that if there is a 0 value the number greater then 0 shifts at second place and greater then 0 values shifts at 1st place.
I do not know how come this is happening.
Here is my code :
$val1 = $this->input->post('current');
$val2 = $this->input->post('graph1');
$val3 = $this->input->post('graph2');
$val4 = $this->input->post('graph3');
$val5 = $this->input->post('graph4');
$filter = array($val1, $val2, $val3, $val4, $val5);
//array(0, '', 2, '', '')
foreach ($filter as $key => $value) {
if (empty($value)) {
unset($filter[$key]);
$filter[] = $value;
}
}
$filter_new = array_values($filter);
//array(2, 0, '', '', '')