Thursday, 25 September 2014

range in PHP

PHP range() function permits to make and fill a array consisting of a range of low and high values.

Syntax:


range(low,high,step)
 
Parameters Description:
 
low : Required. Tags the lowest value of the array.
high : Required. Tags the the highest value of the array.
step : Optional. Determines the increment utilized within the range. Default is 1.
Note : This parameter was added in PHP 5

Example:


<?php
$number = range(0,4);
print_r($number);
$number = range(0,40,10);
print_r($number);
$letter = range("a","e");
print_r($letter);
?>

O/P:


Array ( 
        [0] => 0
        [1] => 1 
        [2] => 2 
        [3] => 3 
        [4] => 4 
) 
Array (
        [0] => 0 
        [1] => 10 
        [2] => 20 
        [3] => 30
        [4] => 40
 ) 
Array (
        [0] => a 
        [1] => b
        [2] => c
        [3] => d 
        [4] => e 
)

0 comments:

Post a Comment