Array help, please

I have a list of network equipment that is continually monitored through ping results. A very ugly HTML file is created using the results of their responses. I have nearly 200 devices being monitored. I am unable to modify the HTML file. I want to create a graphical map of some of the equipment. Most locations have dozens of monitored devices - if I was to place a marker (green/red - up/down) on a map for every device – the map would be saturated.

So what I am trying to do now is create an array with only the devices I want mapped (maybe add the other devices at the same location as a tooltip or similar under the parent location/equipment)

[php]$device = ‘24ap.router.newyork’;

$maps = array( array( Device => “24ap.router.newyork”,
Name => “New York 2.4”,
Top => “246px”,
Left => “131px”),
array( Device => “900ap.router.newyork”,
Name => “New York 900”,
Top => “100px”,
Left => “200px”));

foreach($map as $map_value)
{
if(in_array("$device", $map_value)) {
echo “FOUND! " .$device .”
";
for ($row = 0; $row < 2; $row++) {
echo $map[$row][“Name”]." Absolute positions: “.$map[$row][“Top”].” cross ".$map[$row][“Left”];
echo “
”;
}
}
}[/php]

Results (repeated foreach item in parent array of all monitored devices):

FOUND! 24ap.router.newyork New York 2.4 Absolute positions: 246px cross 131px New York 900 Absolute positions: 100px cross 200px

Im not strong with arrays yet. It took me a while to get this part working :slight_smile:
I’ve got it searching for the $device within my array of mapped-only devices… How can I make it print only this $device’s relevant details - EG only New York 2.4 Absolute positions: 246px cross 131px in this example and not all within the entire array??

First of all, sorry about my english.

Your problem were with the function in_array() this return if first parameter are included at second parameter, but you do an “for” writing always all contents in maps.
if $device are in $maps write all maps.

You can try this code that only print the position of array that are included:

$device = ‘24ap.router.newyork’;

$maps = array(array(Device => “24ap.router.newyork”,
Name => “New York 2.4”,
Top => “246px”,
Left => “131px”),
array(Device => “900ap.router.newyork”,
Name => “New York 900”,
Top => “100px”,
Left => “200px”));

foreach($map as $map_value){
if($device ==$map_value[‘Device’]) {
echo “FOUND! " .$device .”
";
echo $map_value[“Name”]." Absolute positions: “.$map_value[“Top”].” cross ".$map_value[“Left”];
echo “
”;
}
}

Your English is well :slight_smile: Guided me correctly to what I was looking for. Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service