php——理解for(int i : index)

php——理解for(int i : index),第1张

php——理解for(int i : index) 来源

今天看到一篇博主写的文章,是关于java数组下标的用法,感觉挺有意思的就写下来了。我用php语言进行了改写,效果一样的。

方法一:for循环
 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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5717948.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存