Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-13 10:00:34
Original
982 people have browsed it

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...
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