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

藏色散人
Release: 2019-01-29 10:30:45
Original
6326 people have browsed it

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.

PHP displays all numbers between 200 and 250 that are divisible by 4

The code is as follows:

<?php
echo implode(",",range(200,250,4))."\n";
Copy after login

Output:

200,204,208,212,216,220,224,228,232,236,240,244,248
Copy after login

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template