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 112 views
1 answer 130 views
3 answers 222 views
1 answer 108 views
1 answer 127 views
2 answers 191 views
2 answers 201 views
...