3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = "# 12 # # # Hello World"; $strArr = explode(' ', $str); $strArrKeys = array_keys($strArr, '#'); $strArrSplit = array_pop($strArrKeys) + 1; //all after the last # $subArr = array_slice($strArr, $strArrSplit); echo implode(' ', $subArr); //all before the last # (inluding the #). $subArr = array_slice($strArr, 0, $strArrSplit); echo implode(' ', $subArr);
based on DYnWK
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.0
Hello World# 12 # # #