views:

22

answers:

1

I'm fairly proficient in HTML/CSS, but very new when it comes to the likes of PHP and Javascript. I've jumped headfirst into coding Wordpress shortcodes (basically php functions), and so far, through trial and error and seemingly endless browser refreshes, I've been able to figure everything out. I just hit a huge wall though, hence why I'm here.

Basically, I'm trying to give an attribute a list of values like: attr="23, 95, 136, ect"

The function then needs to take that attribute variable and create an array with it: $arr = array($attr);

To me that seems as if it would work, but the array takes the whole list as one value instead. After doing that I want to create a foreach loop that parses each number from the list, possibly through yet another foreach loop if possible, and returns a section of code for each one, and I'm not quite sure how to pull that off either.

Any feedback would be greatly appreciated.

+1  A: 
explode(", ", "23, 95, 136")

gives array(23, 95, 136). See the manual.

If you wish, you can then iterate throw the several values:

$data = "23, 95, 136";
$arr = explode(", ", $data);
foreach ($arr as $value) {
    //$value will take the value 23, then 95, and finally 136
}
Artefacto
cool thanks! I'll try exploding some stuff when I get back later tonight.
matphoto