如何回显每个var超过$ var? [关闭]

I have

$room=$_POST['room'];
$lastMTime=$_POST['lastMTime'];

function _getLastMsg($rName, $lMT){
  $r=$rName.'.xml';
  $rXML=simplexml_load_file($r) or die('Not found');
  $rLMT=$rXML->lastMT;
  if($lMT<$rLMT){
    //some code here
  }
}

How do I echo every $rXML->username that has $rLMT > $lMT? I want to get all usernames that have been submitted after $lMT.

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;
    }
}

First of all make sure that all these vars should not be an array instead. When you have multiple variables which are handled in the same way usually it is a clear sign that they should be an array instead.

If not - you can use compact function to make variable names into array with their names and values, read the manual on it. Other way to access variable value by its name is variable variables - $$

may be you can try this code

<?php
    $var = [11, 10, 20, 30, 40];

    for($i=0; $i<count($var)-1; $i++) {
        if($var[$i]>$var[($i+1)]) {
            echo "var $var[$i] > var ".$var[($i+1)];
        }
    }
?>