How to get the last two words from a string in PHP

1 Answer

0 votes
$s = "php java c# python c++";
  
$arr = explode(' ', $s);
      
echo $arr[count($arr) - 2] . " " . $arr[count($arr) - 1];
 
 
 
   
/*
run:
 
python c++
 
*/

 



answered Sep 6, 2019 by avibootz

Related questions

1 answer 221 views
1 answer 233 views
1 answer 219 views
3 answers 403 views
1 answer 202 views
2 answers 381 views
2 answers 360 views
...