Home >Daily Programming >PHP Knowledge >PHP displays all numbers between 200 and 250 that are divisible by 4
PHP displays all numbers between 200 and 250 that are divisible by 4, we can do this through implode() function and range() function, and in this case we will not use any PHP control statement.
The code is as follows:
<?php echo implode(",",range(200,250,4))."\n";
Output:
200,204,208,212,216,220,224,228,232,236,240,244,248
Required functions:
1.implode() function means converting the value of a one-dimensional array into a string
implode ( string $glue , array $pieces ) : string implode ( array $pieces ) : string
Use glue to connect the value of the one-dimensional array into a string.
Note: implode() can receive two parameter orders, but explode() cannot. However, following the order in the document can avoid confusion.
The parameter glue represents an empty string by default. pieces represents the array you want to convert.
Return value: Returns a string whose content is the value of the array separated by glue.
2.range() function Create an array based on the range, containing the specified elements
range ( mixed $start , mixed $end [, number $step = 1 ] ) : array
Create an array containing the specified range units.
The parameter start represents the first value of the sequence. end represents the value at which the sequence ends at end. step means that if the step size step is set, it will be used as the step value between units. step should be a positive value. If step is not set, it defaults to 1.
Return value: The units from start to end (including start and end) in the returned array.
This article is an introduction to the method of displaying all numbers between 200 and 250 that are divisible by 4 in PHP. I hope it will be helpful to friends in need!
The above is the detailed content of PHP displays all numbers between 200 and 250 that are divisible by 4. For more information, please follow other related articles on the PHP Chinese website!