$i++ * 100, how to?

Discussion in 'PHP' started by Fracisc, Feb 24, 2009.

  1. #1
    I have this code:

    <?
    $i=0;
    
    if (isset($_GET['x'])) { 
    echo "x ".$i++;
    }
    
    if (isset($_GET['y'])) { 
    echo "y ".$i++;
    }
    
    if (isset($_GET['z'])) { 
    echo "z ".$i++;
    }
    
    if (isset($_GET['w'])) { 
    echo "w ".$i++;
    }
    
    ?>
    Code (markup):
    Now, what I need to do is that starting from zero (the first one) I have to increase each GET (if set) with 100.

    Like this:
    if is set get 1 my $i should be 0,
    if is set get 2 my $i should be 100,
    if is set get 3 my $i should be 200,
    if is set get 4 my $i should be 300.

    How can I do that? I have tried to start with a $i=0*100; but that is not working.
     
    Fracisc, Feb 24, 2009 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    $i = 0*100 is equal to zero, therefore its not working.

    Maybe this

    $i=0;
    
    if (isset($_GET['x'])) { 
    echo "x ".$i;
    $i+=100;
    }
    
    if (isset($_GET['y'])) { 
    echo "y ".$i;
    $i+=100;
    }
    
    if (isset($_GET['z'])) { 
    echo "z ".$i;
    $i+=100;
    }
    
    if (isset($_GET['w'])) { 
    echo "w ".$i;
    $i+=100;
    }
    PHP:
    or the simplified version:

    
    $getarray = array('x','y','z','w');
    $i=0;
    foreach ($getarray as $get) {
    if (isset($_GET[$get])) {
    echo $get.' '.$i;
    $i+=100;
    }
    }
    
    PHP:
     
    ads2help, Feb 24, 2009 IP
  3. Fracisc

    Fracisc Well-Known Member

    Messages:
    3,670
    Likes Received:
    10
    Best Answers:
    1
    Trophy Points:
    195
    #3
    Thanks! I managed to do it with

    echo "w ".$i++*100;
     
    Fracisc, Feb 24, 2009 IP