How can you separate and retrieve individual values from a comma-separated list in PHP?
To separate and retrieve individual values from a comma-separated list in PHP, you can use the explode() function to split the string into an array based on the delimiter (in this case, a comma). You can then access each value in the array using its index.
$list = "apple, banana, cherry, date";
$values = explode(", ", $list);
foreach ($values as $value) {
echo $value . "<br>";
}
Keywords
Related Questions
- What are the potential pitfalls of including meta tags in PHP files that are included in the main index.php file?
- In what scenarios would one need to detect the encoding of a string in PHP and how can this be achieved effectively?
- What are the potential pitfalls of including a guestbook on a website using PHP?