PHP: range() function
PHP: Create an array containing a range of elements
The range() function used to create an array containing a range of elements.
Version:
(PHP 4 and above)
Syntax:
range(low_value, high_value, step)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
low_value | Specify the lowest value. | Required | Mixed* |
high_value | Specify the highest value. | Required | Mixed* |
step | It is used as increment between elements. The default value is 1. | Optional | Integer/Float |
*Mixed: Mixed indicates multiple (but not necessarily all) types.
Return value: An array.
Value Type : Array
Example:
<?php
$number_list = range(11,19);
print_r ($number_list);
echo "<br /> ";
$number_list_step = range(11,19,2);
print_r ($number_list_step);
echo "<br /> ";
$letter_list = range("u","z");
print_r ($letter_list);
?>
Output:
Array ( [0] => 11 [1] => 12 [2] => 13 [3] => 14 [4] => 15 [5] => 16 [6] => 17 [7] => 18 [8] => 19 ) Array ( [0] => 11 [1] => 13 [2] => 15 [3] => 17 [4] => 19) Array ( [0] => u [1] => v [2] => w [3] => x [4] => y [5] => z)
Pictorial Presentation:

View the example in the browser
Practice here online :
See also
PHP: Tips of the Day
Filters the collection using the given callback
Example:
<?php function tips_reject($items, $func) { return array_values(array_diff($items, array_filter($items, $func))); } print_r(tips_reject(['Apple', 'Pear', 'Kiwi', 'Banana'], function ($item) { return strlen($item) > 4; })); ?>
Output:
Array ( [0] => Pear [1] => Kiwi )
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises