0
I created an algorithm that checks an array of percentages and returns a status according to the value, but my array STATUS is returning me only the last value. I would like the status array to receive all values within it, for example $percentinstalled[0] = 50, then $status[0] = 'critical', and so on...
<?php
$percentinstalled = array(
0=>'50.0',
1=>'93.1',
2=>'100.0',
3=>'75.2',
4=>'69.0',
5=>'100.0',
6=>'96.7',
7=>'38.7',
8=>'22.7',
9=>'91.6',
10=>'33.3',
11=>'100.0',
12=>'96.9',
13=>'54.3',
14=>'67.2',
15=>'81.9'
);
$status = array();
for ($j = 0; $j <= 15; $j++) {
if ($percentinstalled[$j] >= 98.0) {
$status = array(
$j => "ok",
);
} elseif ($percentinstalled[$j] >= 95.0) {
$status = array(
$j => "warning",
);
} elseif ($percentinstalled[$j] >= 80.0) {
$status = array(
$j => "alert",
);
} elseif ($percentinstalled[$j] <= 79.9) {
$status = array(
$j => "critical",
);
} else {
$status = array(
$j => "Unknow",
);
}
}
foreach ($status as &$val3) {
echo $val3 . "</br>";
}
?>
GOAL:
I have the array $percentinstalled with all values in float, I would like to pass all these values within one IF where according to these values he returns to me what was defined within this exception, that our case would be a string where the value can be: (ok for >= 98.0, Warning for >= 95.0, Alert for >= 80.0, Critical for <= 79.9 or unknow if no value is found). In the current form it is only saving the last array value (position 15), and not all values as desired.
I don’t quite understand what you want to do, can you explain it better? want to pass a couple of values to the array?
– Ricardo Pontual
I have the array
$percentinstalledwith all values infloat, I would like to pass all these values within oneIFwhere according to this value he returns to me what was set within this exception, that our case would be astringwith the value of: (ok, Warning, Alert, Critical or unknow). In the current form it is only saving the last value of the array (position 15), and not all values as desired.– Luis Henrique
Exchange the
$status = array($j => "")for$status[] = array($j => "texto"). So you will concatenate the values. Or, simply:$status[$j] = "texto"– CypherPotato
It worked out, buddy, thanks!
– Luis Henrique