Okay - so I'm creating a dynamic CSS stylesheet, which I want to set up with an array.
First let me say that I'm not a PHP expert, but I somewhat know my way around it.
Here's my very basic array.
$visual_css = array (
array(
"selector" => "body",
"property" => "background",
"value" => "#FFF",
"property2" => "color",
"value2" => "#000",
"type" => "css"
)
);
So we have a selector, and two properties with values.
I now want to create the stylesheet, but I'm running into problems due to my lack of PHP knowledge.
foreach ($visual_css as $value) {
switch ($value['type']) {
case "css":
// Open selector
echo ( !empty($value['selector']) ? $value['selector'] . '{' : null );
foreach ($value as $key => $item) {
foreach ($value as $key2 => $item2) {
//Match only the id's against the key
if (preg_match('/^property/i', $key) && preg_match('/^value/i', $key2)) {
// First property
echo ( !empty($item) ? $item . ':' : null );
echo ( !empty($item2) ? $item2 . ';' : null );
}
}
}
// Close selector
echo ( !empty($value['selector']) ? '}' : null );
break;
}
}
Now I know this code isn't correct, as it's outputting the following in the stylesheet:
body{background:#FFF;background:#000;color:#FFF;color:#000;}
This is the desired result:
body{background:#FFF;color:#000;}
So basically, I want to be able to create an unlimited number of properties and values with an incrementing number after them, and have the code write it out.
Can anyone help me?
Thanks!