Home  >  Article  >  Backend Development  >  How to output how many palindromes there are between two numbers in PHP_PHP Tutorial

How to output how many palindromes there are between two numbers in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:00:34943browse

How to output the number of palindromes between two numbers in PHP

This article mainly introduces the method of outputting the number of palindromes in the middle of two numbers in PHP. Examples analyze the concept of palindrome numbers and related judgment skills. Friends in need can refer to it

The example in this article describes how PHP outputs how many palindromes there are between two numbers. Share it with everyone for your reference. The specific analysis is as follows:

"Palindrome" is a type of number. For example: 98789, this number is read as 98789 upright, and it is also 98789 when read backwards. It is the same when read upright and backward, so this number is a palindrome number.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

for($i=10;$i<100;$i ){

$len=strlen($i);

$l=1;

$k=intval($len)/2 1;

for($j=0;$j<$k;$j ){

if (substr($i,$j,1)!=substr($i,$len-$j-1,1))

$l=0;

break;

}

if ($l==1)

echo $i.'
';

}

?>

1 2

3

4 5

67 8 9 10 11 12
13
14
<๐ŸŽœ>for($i=10;$i<100;$i ){<๐ŸŽœ> <๐ŸŽœ>$len=strlen($i);<๐ŸŽœ> <๐ŸŽœ>$l=1;<๐ŸŽœ> <๐ŸŽœ>$k=intval($len)/2 1;<๐ŸŽœ> <๐ŸŽœ>for($j=0;$j<$k;$j ){<๐ŸŽœ> <๐ŸŽœ>if (substr($i,$j,1)!=substr($i,$len-$j-1,1))<๐ŸŽœ> <๐ŸŽœ>$l=0;<๐ŸŽœ> <๐ŸŽœ>break;<๐ŸŽœ> <๐ŸŽœ>}<๐ŸŽœ> <๐ŸŽœ>if ($l==1)<๐ŸŽœ> <๐ŸŽœ>echo $i.'
'; } ?>
I hope this article will be helpful to everyoneโ€™s PHP programming design. http://www.bkjia.com/PHPjc/973129.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973129.htmlTechArticleHow does PHP output how many palindromes there are between two numbers? This article mainly introduces how PHP outputs two numbers. How many palindromes are there in the middle of a number? The concept and correlation of palindromes are analyzed with examples...
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