doyz51819 2019-02-25 19:57
浏览 192
已采纳

PHP:如何从数组中的每个字符串中删除前两个字符?

Have:

[0] => 0-3019
[1] => 0-3020
[2] => 0-1031
[3] => 0-3021
[4] => 0-1004
[5] => 0-3011

Want:

[0] => 3019
[1] => 3020
[2] => 1031
[3] => 3021
[4] => 1004
[5] => 3011

Not sure how to get rid of it, tried this.

Edit: Here is the code I've tried:

$files = array_keys($_FILES);

foreach ($files AS $f) {
    $f = substr($f,2);
}

For some reason it works inside the forloop but isn't actually saving each element as the substring version of itself :(

  • 写回答

2条回答 默认 最新

  • douzhuo1853 2019-02-25 20:26
    关注

    You can reference & each exposed element in order to change the original:

    foreach ($files as &$f) {
        $f = substr($f, 2);
    }
    

    Or modify the original array using the key:

    foreach ($files as $k => $f) {
        $files[$k] = substr($f, 2);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器