Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: looping arrays

  1. #1
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    looping arrays

    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 Code:
    <?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()
    ?>
    The problem is IE

  • #2
    New Coder
    Join Date
    May 2003
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Personally, I would use:
    PHP Code:
    trim($v3) != "" 
    cpCommerce - Finally a template based open-source e-commerce solution

  • #3
    New Coder
    Join Date
    Sep 2002
    Location
    Australia
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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() 
    ?>
    The problem is IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •