Explode only by last delimiter

后端 未结 11 1734
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 17:30

is there a way to use explode function to explode only by last delimiter occurrence?

$string = "one_two_  ... _three_four";

$explodeResultArray = e         


        
11条回答
  •  庸人自扰
    2021-01-03 18:26

    // reverse $string right after definition
    $string = "one_two_three_four_five_six";
    $string = implode("_",array_reverse(explode("_",$string)));
    
    // chop off the first part
    list($result, $string) = explode("_", $string, 2);
    
    echo "$result --- $string";
    

    Output:

    six --- five_four_three_two_one 
    

提交回复
热议问题