sentence get first second word php laravel 1

sentence get first second word php laravel

// Example 1
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

output:
//piece1
//piece2

Here is what the above code is Doing:
1. We create a string variable called $pizza and assign it a string value.
2. We create a variable called $pieces and assign it the value of the explode() function.
3. The explode() function breaks up the string we pass to it (in this case, $pizza) wherever it finds the string we specify (in this case, a space).
4. The explode() function returns an array of strings it created, and we save that array in the $pieces variable.
5. We echo out the first and second elements of the $pieces array.

Similar Posts