[Solved] How to echo every var more than $var? [closed]


Using the variables into your example you can do this

$i = 0;
while ($i <= 3) {
    $varName="var".$i;
    if ($$varName > $var) {
        echo $$varName;
    }
    $i++;
}

But that is no right way to iterate over an array. There exists a million other ways to iterate over a bunch of variables and print them, all of them are not the “right” way to do it. In your example code there is no array, where there should be one. Like this

$var = 11;
$vars = [10, 20, 30, 40];

# iterate and echo each element of $vars array)
foreach ($vars as $current) {
    if ($current > $var) {
        echo $var;
    }
}

4

solved How to echo every var more than $var? [closed]