Free cookie consent management tool by TermsFeed Generator PHP range | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
PHP range

PHP range

Last Updated on Feb 15, 2023

Range

Range is a function that creates an array containing the range of elements

It takes 3 arguments

range(start,end,step)

Start is the first value

End is the last value

Step is the increment between first and last values default is 1

So let’s see some examples

A sequence of numbers between 1 and 6

$range = range(1,6);
print_r($range);
// Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 )

A sequence of numbers between 1 and 6 with increments of 2 (step 2)

$range = range(1,6,2);
print_r($range);
// Array ( [0] => 1 [1] => 3 [2] => 5 )

Conclusion

Now you know range funciton in PHP.

I recommend you to open a PHP file and try to define different ranges. Then try different steps for all those ranges.

If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!

Key takeaways

  • range function in php
  • steps in a range

Category: programming

Tags: #php #array

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

undo git merge the easy way and then undo the undoing! (video)
Nov 27, 2022 programming

undo git merge the easy way and then undo the undoing! (video)

we are going to talk about how to undo git merge and then we talk about how to undo the undoing ...

9 Min Read Read More
PHP Operators
Mar 21, 2023 programming

PHP Operators

Today we are going to learn about Operators in PHP including arithmetic, comparison and logic operators. You will be using all of these operators during your career a lot. ...

5 Min Read Read More
PHP random number
Feb 15, 2023 programming

PHP random number

Today we are going to talk about generating random numbers in PHP. Knowing how to generate a random number is more useful than you think. you can select random users and much more. ...

3 Min Read Read More
PHP array change key case
Feb 14, 2023 programming

PHP array change key case

Today we are going to talk about changing the case of the keys of an array in PHP. Sometimes you might change the case of the keys in your array. It's very easy to do that in PHP. ...

4 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...