Jump to content

changing key and value inside array


tomasd

Recommended Posts

Hi,
I have this code here
[code]
<?php
$sys = snmprealwalk("192.168.100.100", "cisco1720", ".1.3.6.1.2.1.17");
$sys = array_flip($sys);
print_r ($sys);
?>
[/code]

Which on execution produces:[pre] [wally@macppc dhcp]$ php test.php
Array
(
    [Hex-STRING: 00 04 DC 0C EA AF ] => SNMPv2-SMI::mib-2.17.1.1.0
)[/pre] My questions are:
how to get rid of "Hex-STRING: " and last space " " from the key and "SNMPv2-SMI::" from the value within the array itself?
[i]I've looked for array functions but could not find right one.[/i]
how to insert ":" beween xx xx xx xx xx so I get right mac address notation i.e. xx:xx:xx:xx:xx

Thanks everyone for your help!!!
Link to comment
https://forums.phpfreaks.com/topic/17597-changing-key-and-value-inside-array/
Share on other sites

try this..

[code]<?php

function formatArray ($array)
{
    if (!is_array($array)) return false;

    $return = array();

    foreach ($array as $key => $val)
    {
        $key = trim(substr($key, 12));
        $val = trim(substr($val, 12));

        $key = str_replace(' ', ':', $key);

        $return[$key] = $val;
    }

    return $return;
}

$sys = snmprealwalk("192.168.100.100", "cisco1720", ".1.3.6.1.2.1.17");
$sys = formatArray($sys);

?>[/code]untested.
  • 3 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.