PHP Arrays Initializing an Array to a Range of Integers - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Arrays Initializing an Array to a Range of Integers - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, May 17, 2019

PHP Arrays Initializing an Array to a Range of Integers

PHP Arrays



Initializing an Array to a Range of Integers

Problem

You want to assign a series of consecutive integers to an array.

Solution

Use range($start, $stop):
         
               $cards = range(1, 52);

Discussion

For increments other than 1, pass an increment to range() as a third argument.

So for odd numbers:

              $odd = range(1, 52, 2);

And for even numbers:

              $even = range(2, 52, 2);



No comments:

Post a Comment

Post Top Ad