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 144 views
1 answer 161 views
3 answers 266 views
1 answer 138 views
1 answer 159 views
1 answer 125 views
2 answers 256 views
...