...

View Full Version : looping arrays



oztinks
05-13-2004, 10:05 AM
Hi,
I have my script returning this from a form
body { line-height: normal;
color: transparent;
font-weight: normal;
font-style: normal;
text-decoration: none;
text-align: left;
background-color: transparent;
}

but I need to ignore $v2 and $v3 if $v3 is normal or transparent making it return
body {
font-size: 12px ;
color: black;
text-decoration: none;
text-align: left;
background-color: white;
}
I have tried
if (!empty($v3)||( $v3 != 'normal'))
but then the !empty dosen't work




<?php function makecss(){
global $style;
foreach ($style as $key => $value) {
echo "$key {";
foreach ($value as $v2 => $v3) {
if (!empty($v3)){
echo " $v2: $v3; \n ";}
}
echo "}\n";
}
}
makecss()
?>

cpradio
05-13-2004, 05:32 PM
Personally, I would use:

trim($v3) != ""

oztinks
05-14-2004, 12:42 AM
Thanks cpradio,
but I can't get the trim function to return the right results.
I ended up nesting a few if statments to filter the result seems a bit long winded but it is working


<?php
$style = array('body' => array('color'=> 'black','width'=>'100px','font-family'=>'verdana'),
'div' => array('color'=> '', 'font-size'=>'normal','font-family'=>'arial'),
'.small'=>array('color'=> 'transparent','font-size'=>'8px','text-align'=>'left'));
function makecss(){
global $style;
foreach ($style as $key => $value) {
echo "$key {\n";
foreach ($value as $v2 => $v3) {
if ($v3 != 'normal'){
if ($v3 != 'transparent'){
if ($v3 != 'left'){
if (!empty($v3)){
echo "$v2: $v3; \n ";
}
}
}
}
}
echo "}\n";
}
}
makecss()
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum