PHP Personal how to list array that are with the limit less than 30 min

Asked

Viewed 59 times

0

Staff I commented in the code below what I need I hope you understand me if someone can give a force here thank you

I know very little of php thank you !

<?php
// Fazemos o Comando que queremos no Mikrotik
if ($API->connect($ip, $login, $senha)) {
$ARRAY = $API->comm("/ip/hotspot/user/print");
// Preparamos o Loop
for ($i = 0; $i < count($ARRAY); ++$i)
{
$resultado = $ARRAY[$i];
//print_r($ARRAY);
?>



 <?php echo  $resultado['limit-uptime'];?> 

acima  vem as respostas no echo exemplo:
usuario: 30m
usuario menor que 29m 

quero apenas que lista os usuários que que estao com o tempo menor que 30m






<?php } /* Fechamos o While */ ?>
<?php } /* Fechamos o IF */ ?>

  • $resultado['limit-uptime'] prints exactly that usuario: 30m? Or just the value?

2 answers

1

Hello, you can try like this:

change $resultado = $ARRAY[$i]; for:

if ($ARRAY[$i]['limit-uptime'] < 30) {

    $resultado = $ARRAY[$i];
}

when you put the variable $resultado within the if it will only receive the data if it is according to the condition you placed in the if

  • Careful. The way you’re standing, '30' is a string and not a number. Assuming that limit-uptime is already a number, the correct thing is to do: $ARRAY[$i]['limit-uptime'] < 30

  • Independent. In your example, you’re comparing something that we don’t know about with a string. 30 is a number, '30' is a string and not a numeric value

  • ah yes, I understood then.

1

You need to extract string time as a whole number to compare if it is less than 30. Add this code inside the for:

$tempo = filter_var($resultado['limit-uptime'], FILTER_SANITIZE_NUMBER_INT);

if ($tempo < 30) {
    echo 'Tempo menor que 30m';
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.