Skip to content

Instantly share code, notes, and snippets.

@freretuc
Created October 3, 2011 16:02
Show Gist options
  • Save freretuc/1259459 to your computer and use it in GitHub Desktop.
Save freretuc/1259459 to your computer and use it in GitHub Desktop.
Delete empty array element (with sort)
<pre><?php
$arr[] = "b";
$arr[] = "";
$arr[] = "aa";
$arr[] = "c";
$arr[] = "";
$arr[] = "da";
print_r($arr);
sort($arr);
print_r($arr);
while(trim($arr[0]) == '' && count($arr) > 0) {
array_shift($arr);
}
print_r($arr);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment