How can the explode() function in PHP be used to split a string into individual words in an array?
To split a string into individual words in an array using the explode() function in PHP, you can use a space (' ') as the delimiter. This will separate the string at each space and store each word as an element in the resulting array. You can then access each word in the array using its index.
$string = "Hello world";
$words = explode(" ", $string);
print_r($words);
Related Questions
- Are there any alternative methods or libraries in PHP that can be used for more accurate time calculations and formatting?
- What are some best practices for optimizing PHP code to avoid performance issues like infinite loops?
- What best practices should be followed when combining HTML output and database queries in PHP scripts?