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
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.
Link to comment
Share on other sites

  • 3 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.