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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失