LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP set of variables increment? (https://www.linuxquestions.org/questions/programming-9/php-set-of-variables-increment-194684/)

Ctawp 06-17-2004 02:41 PM

PHP set of variables increment?
 
Alright, so I'm wondering if there is any way to do something like the following:

while ($count<8){
echo $i_need_incremented_"$count";
$count++;
}

such that the echo outputs what is contained inside $i_need_incremented_0 the first time, $i_need_incremented_1 the second time, and so on.

-Chris

keefaz 06-17-2004 02:46 PM

PHP Code:

while ( $count 
{
    echo 
"\$i_need_incremented_$count";
    
$count++;



Ctawp 06-17-2004 03:32 PM

that doesn't output the contents of it though?

keefaz 06-17-2004 03:56 PM

Well I am sorry ;)
PHP Code:

while ( $count )
{
    echo ${
"i_need_incremented_$count"};
    
$count++;



Ctawp 06-17-2004 04:03 PM

Awesome, thank you thank you. :) You're my new best friend.

Ctawp 06-18-2004 11:00 AM

Any way for php to parse this so I can use that specific variable in an if statement kinda thing?

-Chris

keefaz 06-18-2004 01:03 PM

PHP Code:

while ( $count )
{
    
$tmp = ${"i_need_incremented_$count"};

    if( 
$tmp == "You know what" )
    {
        echo 
"I know that\n";
    }




All times are GMT -5. The time now is 04:45 PM.