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

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 Unique
Feb 14, 2023 programming

PHP Array Unique

Today we are going to talk about array unique function in PHP. It's a very good way to remove duplicated values from an array and change it to an array of unique values. ...

5 Min Read Read More
PHP Simple Tinker Like Script
Feb 15, 2023 programming

PHP Simple Tinker Like Script

Today we are going to build a simple Tinker in PHP. Tinker is a tool that allows users to interact with the application through the command line. ...

8 Min Read Read More
React Beginner to Advance 2025: A Complete Guide to Building Modern Web Applications
Jul 18, 2025 programming

React Beginner to Advance 2025: A Complete Guide to Building Modern Web Applications

React JS has firmly established itself as one of the most widely adopted JavaScript libraries for building dynamic user interfaces. Whether you're crafting a small personal website or architecting a large-scale enterprise dashboard, React's component-based architecture and flexible ecosystem allow developers to create highly performant, scalable, and maintainable applications. ...

29 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 ...