Micheal Micheal - 6 months ago 8
PHP Question

Php Explode string and out put each string without showing array

I have something saved in my database like this

PHP,HTML,CSS,SQL,JQUERY,....


More can stile show or it might end up being 2 or 1 depending on how may saved for current viewing post.

Now i need to Output each string separately see below example

echo $str1; Output = PHP,

echo $str2; Output = HTML,

echo $str3; Output = CSS,

echo $str4; Output = JQUERY,


I tried using this but i don't understand what is showing me please i need help with it

Here is my code

<?php
$str = 'one,two,three,four';

print_r(explode(',',$str,0));

print_r(explode(',',$str,2));

print_r(explode(',',$str,-1));
?>


And the out put is this, is not what i want

Array ( [0] => one,two,three,four )
Array ( [0] => one [1] => two,three,four )
Array ( [0] => one [1] => two [2] => three )

Answer

Use array!

<?php
$str = 'one,two,three,four';

$array= explode(',',$str);

//Print each array element 
//('one' 'two' 'three' 'four' an so on...)
foreach($array as $element){
    echo $element;
}
?>