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 Namespace
Mar 23, 2023 programming

PHP Namespace

Today we are going to talk about namespaces in PHP. Namespace is like putting the classes in a group. it helps you organize your code much better. It's a must-know topic for a PHP programmer. ...

7 Min Read Read More
PHP catch exceptions
Feb 14, 2023 programming

PHP catch exceptions

Today we are going to talk about catching exceptions in PHP. Most of the time in your script you might face some exceptions. So today we are going to learn how to catch those exceptions. ...

7 Min Read Read More
Machine Learning in PHP
Mar 18, 2023 programming

Machine Learning in PHP

Machine learning is a way for computers to learn and improve at tasks without being specifically programmed to do so. Are you curious about machine learning and PHP? ...

10 Min Read Read More
How to Combine Excel Files Using Python
May 08, 2024 programming

How to Combine Excel Files Using Python

Sometimes you might have many excel files that you need to combine, whether it's reports, user data or anything else, merging them into one file with Python can be easily done. ...

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