php - reading and removing a substring in the most efficient way possible, like array_pop() but for sub strings -


i have string of following. in other words, may have "in morning" or "in evening" sometimes, may not have anything.

"bla bla in morning" or  "bla bla bla in evening" or  "bla bla bla" 

does php have function both isolate , remove sub string @ same time? $last_in_array = array_pop($arr); both saves last element $last_in_array , removes array @ same time. strings scenario i'm explaining. if not, what's efficient way this?

function string_pop(&$haystack, $needle) {     if (strpos($haystack, $needle) !== false) {         $haystack = str_replace($needle, "", $haystack);         return $needle;     }     return false; }  $string = "bla bla in morning"; $return = string_pop($string, " in morning");  var_dump($string); var_dump($return); 

output:

$string: string(7) "bla bla" $return: string(15) " in morning" 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -