Home >Backend Development >PHP Tutorial >大家帮忙看下这段代码哪有问题

大家帮忙看下这段代码哪有问题

WBOY
WBOYOriginal
2016-06-23 14:15:26978browse

<?php$str='abcdefghijklmnopqrstuvwxyz'; $count = 123456789;$str1 = $str[floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26)];$str2 = $str[floor(floor(floor(floor($count/26)/26)/26)/26)%26];$str3 = $str[floor(floor(floor($count/26)/26)/26)%26];$str4 = $str[floor(floor($count/26)/26)%26];$str5 = $str[floor($count/26)%26];$str6 = $str[$count%26];echo $str1.'<br/>';echo $str2.'<br/>';echo $str3.'<br/>';echo $str4.'<br/>';echo $str5.'<br/>';echo $str6.'<br/>';?>

报这个错:Notice: String offset cast occurred in E:\www\rand.php on line 5


回复讨论(解决方案)

考察一下

$n = floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26);var_dump($n);
float(10)

下标应该是整型数,所以
$str1 = $str[floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26)];
应写作
$str1 = $str[intval(floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26))];

考察一下

$n = floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26);var_dump($n);
float(10)

下标应该是整型数,所以
$str1 = $str[floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26)];
应写作
$str1 = $str[intval(floor(floor(floor(floor(floor($count/26)/26)/26)/26)/26))];

版主强大哈,我半天都不知道从何处手呢

我后来直接用(int)强制转了下成功了。

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