array_filter demo : array_filter « Data Structure « PHP






array_filter demo

 
<?php 
function array_display($array, $pre=FALSE) { 
    $tag = $pre ? 'pre' : 'p'; 
    printf("<%s>%s</%s>\n", $tag, var_export($array, TRUE), $tag); 
} 

$arr = array(2, 'two', 0, 'NULL', NULL, 'FALSE', FALSE, 'empty', ''); 

$copy = array_filter($arr); 

$reindexed = array_values($copy); 


array_display($arr, TRUE); 
print '<p>Filtered:</p>'; 
array_display($copy, TRUE); 
print '<p>Filtered and reindexed:</p>'; 
array_display($reindexed, TRUE); 
?>
  
  








Related examples in the same category

1.Array filter
2.Filtering Arrays Using array_filter()
3.Using the array_filter() Function
4.array_filter( ) filters elements through a function