Quantcast
Viewing all articles
Browse latest Browse all 3

PHP explode foreach

PHP explode() in combination with foreach is a nice way to format comma separated values from string.

Consider following code:

    $str = "alfa, bravo, charlie";
    foreach (explode(',', $str) as $val)  {
	echo $val.'<br>';
    }

This will output:
alfa
bravo
charlie

Here you can see that explode() builds up an array of values which is immediately iterated in foreach loop.


Viewing all articles
Browse latest Browse all 3

Trending Articles