You'd need to walk through the array, and every time an element is empty, shift all the items further in the array down one. You could write each of these steps as two different functions to clean it up a bit.
Here's my quick shot at it, I haven't tested or compiled:
<?php
/********************
a function that shifts items
in array named $array
down by one from $array[$curindex]
onward.
returns the changed array.
********************/
function shiftdown($array, $curindex) {
$len = count($array); // length of array
// do it for each index from $curindex onward
for ($i = $curindex; $i < $len - 1; $i++) {
// copy next element to current one
$array[$i] = $array[$i + 1];
}
return $array;
}
/***************************
removes empty elements from $array
returns changed array
**************************/
function removeemptyelements($array) {
// find number of elements in array
$len = count ($array);
$i = 0; // counter
while ($i < $len) {
if ($array[$i] == "") {
// this element is empty
// shift it down
$array = shiftdown($array, $i);
$len--; // array is one shorter. change length count
}
$i++;
}
}
// testing code
$myarray = {"hi", "you", "" , "yes", "no"};
$myarray = removeemptyelements($myarray);
for ($i = 0; $i < count($array); $i++) {
echo $array[$i] . "\n";
}
?>
kind regards,
--harlan