How to use range in PHP
In this article, I will explain how the range() function can be used in PHP.
range() function in PHP
Syntax
Parameter
- low low is required parameter. Determine the lowest value of the array.
- high high is required parameter. Determine the highest value of the array.
- step step is optional parameter. Determine the increment used in the array. Default value is 1.
Example
The following example show to how the range() function can be used in PHP.
<html>
<body>
<h3 style="color: Blue;">range() function example in PHP</h3>
<?php
echo"First range demo 1-10: ";
foreach (range(0, 10) as $num) {
echo "$num, ";
}
echo "<br />";
echo "Second range demo : ";
foreach (range(0, 100, 10) as $num) {
echo "$num, ";
}
echo "<br />";
echo "Third range demo : ";
foreach (range('a', 'n') as $letter) {
echo "$letter, ";
}
echo "<br />";
echo "Fourth range demo : ";
foreach (range('d', 'a') as $letter) {
echo "$letter, ";
}
echo "<br />";
?>
</body>
</html>
|
Output
You may also want to read these related articles here
Ask Your Question
Got a programming related question? You may want to post your question here