今天看到一篇博主写的文章,是关于java数组下标的用法,感觉挺有意思的就写下来了。我用php语言进行了改写,效果一样的。
public function tel1(){
$arr = [8,2,1,0,3];
$index = [2,0,3,2,4,0,1,3,2,3,3];
$tel = "";
for($i=0;$i
方法二:foreach
public function tel2(){
$arr = [8,2,1,0,3];
$index = [2,0,3,2,4,0,1,3,2,3,3];
$tel = "";
foreach($index as $item){
$str = $arr[$item];
$tel .= $str;
}
return $tel;
}
输出结果
18013820100



