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 218 views
1 answer 231 views
1 answer 216 views
3 answers 398 views
1 answer 198 views
2 answers 380 views
2 answers 357 views
...