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 137 views
1 answer 155 views
3 answers 253 views
1 answer 130 views
2 answers 246 views
2 answers 234 views
1 answer 182 views
...