search
HomeDaily ProgrammingPHP KnowledgePHP 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.

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";

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool