Zend - The PHP Company




Arrays

Add Code


array filter by interval  

Type: code fragment
Added by: alex_vlad
Entered: 15/12/2004
Last modified: 01/12/2004
Rating: - (fewer than 3 votes)
Views: 3309
this function return array B from array A by N interval Since i element


<?php
function filter_by_interval($a,$i,$interval)
{
    
$count count($a);
    
    for( 
$i $i 1$i $count$i++ ) {
    
        
$ar[] = $a[$i];
        
$i+=$interval;
      
    }
    return 
$ar;
}
?>


Usage Example


<?php
$a 
= array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);


$ar filter_by_interval($a,5,2);

for( 
$i 0$i count($ar); $i++ )
echo 
$ar[$i]."<br>";
?>


Rate This Script





Search



This Category All Categories