Home  >  Article  >  Backend Development  >  How to add connectors between numbers in PHP

How to add connectors between numbers in PHP

藏色散人
藏色散人Original
2018-12-04 15:37:037069browse

PHP implements adding connectors between numbers. We can do this through the for loop idea in PHP. The connector here refers to the "-" symbol.

How to add connectors between numbers in PHP

Recommended reference: "PHP Tutorial"

Then it may be difficult for novices.

Let’s use a simple code example to introduce how to add hyphens between numbers in PHP.

Add connectors between numbers 1 to 10 and output.

The code example is as follows:

<?php
for($x=1; $x<=10; $x++)
{
    if($x< 10)
    {
        echo "$x-";
    }
    else
    {
        echo "$x";
    }
}

The result is as shown in the figure below:

How to add connectors between numbers in PHP

As shown in the figure, we successfully moved between the numbers Added connectors, also known as hyphens.

Isn’t it very simple to achieve this effect? We only need to output the variable through the for loop and follow the "-" symbol directly after the variable!

This article is an introduction to the method of adding connectors between numbers in PHP. It is very simple and easy to understand. I hope it will be helpful to friends in need!

The above is the detailed content of How to add connectors between numbers in PHP. 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
Previous article:What is a domain nameNext article:What is a domain name

Related articles

See more