Here is a short sample of the object I am working with.
{
"myservices": [
{
"name": "oozie",
"hostidn": "1",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "2",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "3",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "4",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "oozie",
"hostidn": "5",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
},
{
"name": "single-namenode",
"hostidn": "2",
"details": "failed process health monitor....",
"currstatus": "Warning",
"currstatusclass": "warning"
}
]
}
I ultimately want to find what the highest “hostidn” is before running through all these and displaying them. hostidn is a Nth number it can be the only number or it can be hundreds deep with several duplicates in between. My Goal is to find that highest one and do a for or while loop on it based on that to group them together in a visual display. Example notice I have one hostidn below with the number 2 while all the rest have there own. I would want to group the two with 2 together in a box for display but there is 5 different hostidn in this scenario. I dunno maybe I am thinking it over wrong I’ll take suggestions however.
basic algo you can follow
declare and set a variable to zero like
$currentHighest=0;
then iterate over the json array and on each iteration campare the value of
hostidnwith the$currentHighestif the value is higher than the value already existing in the$currentHighestset that value to$currentHighestat the end of the iteration you will get the highest value in the
$currentHighestTried and tested