3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testing_string = "OFFER_TYPE_1"; $array = explode("_", $testing_string); var_dump($array); $index = intval(end($array))-1; //array index start from 0, while for user readability index starts at 1 unset($array[key($array)]); echo implode("_", $array);
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(3) { [0]=> string(5) "OFFER" [1]=> string(4) "TYPE" [2]=> string(1) "1" } OFFER_TYPE

preferences:
174.04 ms | 403 KiB | 213 Q