search
Homephp教程php手册PHP:统计两个数字中间有多少个回文数

所谓回文数,其实和回文字符串是一样,都是左往右看和从右往左看是一样的。所不同的是,一个是字符串,一个是数字。回文同是他们的特征。如果,你想知道,从999到999999999之间的回文数量,你会怎么处理呢,是数着呢,还是找别人一起数着呢。无疑地,不管人

所谓回文数,其实和回文字符串是一样,都是左往右看和从右往左看是一样的。所不同的是,一个是字符串,一个是数字。回文同是他们的特征。如果,你想知道,从999到999999999之间的回文数量,你会怎么处理呢,是数着呢,还是找别人一起数着呢。无疑地,不管人数的多少,这将是一个简单却又工作量巨大的事情。如果你真的遇上这样的问题了,那可以通过下面的代码进行处理:

<?php 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.&#8217;<br>’;   
}   
?>  

扩展阅读:《PHP:判断一个字符串是否为回文字符串》

转载请注明:IT路人 » PHP:统计两个数字中间有多少个回文数

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools