1

i need to call similar variable on shortest way.

$test = new stdClass();    
$test->var0=0;    
$test->var1=1;    
$test->var2=2; 

And now i need to echo all 3 variables in for cycle, not like this:

echo $test->var0;   
echo $test->var1;
echo $test->var2;
0

1 Answer 1

3

Try this -

for($i = 0; $i < 3; $i++) {
    echo $test->{'var' . $i};
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, saved my day :)
@eddieh accept the answer it will help to other who also facing same issue by click on the left tick

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.