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 upload file
Feb 15, 2023 programming

PHP upload file

Today we are going to talk about uploading a file in PHP. Uploading a file is simple but it's very important to know how to handle uploading the files correctly and securely. ...

7 Min Read Read More
PHP Dependency Management
Mar 22, 2023 programming

PHP Dependency Management

Today we are going to talk about dependency management in PHP. Your code might depends on some packages. You need a way to manage all the dependencies in PHP. ...

9 Min Read Read More
PHP Array Sort
Feb 14, 2023 programming

PHP Array Sort

Today we are going to talk about sorting arrays in PHP. we will take a look at some of the most useful and common array sort functions in PHP and compare their functionality. ...

7 Min Read Read More
Laravel 12 Beginner to Advanced: Complete Guide
Jul 17, 2025 programming

Laravel 12 Beginner to Advanced: Complete Guide

Laravel is a name that resonates throughout the PHP community. With its elegant syntax, robust ecosystem, and developer-friendly tools, Laravel has become the go-to framework for modern web development. Laravel 12, released on February 24, 2025, continues this tradition, streamlining workflows and boosting performance with support for the latest PHP advancements. ...

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