-1
<?php
$all = array();
enter code here
for($i = 1 ; $i <= 100 ; $i++){
$ric=sqrt($i);
if(is_int($ric) == true){
    $all[] = $i;
    
}
}
$max = max($all);
$min = min($all);
echo "MIN=".$min."<br>";
echo "MAX=".$max;

Hello I changed my codes and instead of if((int)$ric - $ric == 0) I write this if(is_int($ric) == true) but it gets me wrong.What is the problem? please help me out.

ALIMOW
  • 5
  • 2
  • 1
    assuming `max()` is the PHP inbuilt `max()` it is used to find the largest value in an array. You dont have and have not created an array – RiggsFolly Aug 05 '20 at 15:52
  • Add [error reporting](http://stackoverflow.com/questions/845021/) to the top of your file(s) _while testing_ right after your opening PHP tag for example. Even if you are developing on a server configured as LIVE you will now see any errors. ` – RiggsFolly Aug 05 '20 at 16:14

1 Answers1

5

Put all the $i that satisfy the condition into an array. You can then use the min() and max() functions to get the minimum and maximum values.

<?php
$all_i = [];
for($i = 1 ; $i <= 100 ; $i++){
    $ric=sqrt($i);
    if((int)$ric - $ric == 0){
        $all_i[] = $i;
    }
}
$max_i = max($all_i);
$min_i = min($all_i);
echo "Min = $min_i<br>Max = $max_i<br>";
echo "All = " . implode(", ", $all_i) . "<br>";
?>
Barmar
  • 741,623
  • 53
  • 500
  • 612