我的问题是如何显示字符串作为使用PHP循环的模式,如果字符串是计算机,第一次迭代它将显示“C”,然后第二次迭代它将显示像“co”等。下面给出的代码,请给出解决方案。如何显示一个字符串模式使用PHP循环
<?php
$array = "computer";
$count = strlen($array);
for($i=0;$i<=$count;$i++)
{
echo $array[$i]."<br>";
}
?>
output will print like this
c
co
com
comp
compu
'$ input ='computer'; echo implode('
',array_map(function($ n)use($ input){return substr($ input,0,$ n);},range(1,strlen($ input))));' - damnit这是不是CodeGolf再... –
“请给解决方案” - *叹* – domsson