Scope Woes - IF statement nested in WHILE statement -PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hdogg
    New Member
    • Mar 2007
    • 7

    Scope Woes - IF statement nested in WHILE statement -PHP

    Scope Woes - IF statement nested in WHILE statement -PHP

    I have an array $actuals_sum.
    <?php
    while(condition s)
    {


    if($i == '24)
    {

    $actuals_sum[$j] = 'bar';

    $j = $j + 1;
    }

    }


    echo $actuals_sum[1];

    ?>
    ---------


    but.... it throws an ERROR and says $actuals _sum is undefined....

    So the scope is LOCAL, i need to make it return GLOBAL.

    -Hyrum
    Reply With Quote
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    #2
    Originally posted by hdogg
    Scope Woes - IF statement nested in WHILE statement -PHP

    I have an array $actuals_sum.
    <?php
    while(condition s)
    {


    if($i == '24)
    {

    $actuals_sum[$j] = 'bar';

    $j = $j + 1;
    }

    }


    echo $actuals_sum[1];

    ?>
    ---------


    but.... it throws an ERROR and says $actuals _sum is undefined....

    So the scope is LOCAL, i need to make it return GLOBAL.

    -Hyrum
    Reply With Quote

    you aren't entering your if statement cause you have single quote before the 24 it you want to check if it is a string then you will need another single quote if you want it to be an int then you need to get rid of the first single quote

    eric

    Comment

    Working...