array_slice():-

The array_slice() function returns selected parts of an array.

implode():-

The implode() function returns a string from the elements of an array.

explode():-

The explode() function breaks a string into an array.

 code:-

<?php

$str = 'php is favourite programming language';

echo implode(' ', array_slice(explode(' ', $str), 0, 4))."\n";

?>

output:-

'php is favourite programming 

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post