Array help.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am processing v4IP's and what I want to do is a prefix substitution
if the 3rd octet matches a predefined list $groupMappings. I went down
this  path and it isn't working as expected. Drawing a blank on this
one. Why does 40 miss the comparison?

$hostname = "Z";
$ips = array('10.1.40.1','10.1.41.1','10.1.1.1','10.1.40.1','10.9.1.1');

foreach ($ips as $ip) {

    $groupMappings = array('40' =>'A','41' =>'B','1' =>'C');

    $ocTest = explode(".", $ip);
    $groupKeys = array_keys($groupMappings);
    $groupTest = array_search("$ocTest[2]", $groupKeys);

    if($groupTest != FALSE) {
        $hostGroup = $groupMappings[$groupKeys[$groupTest]];
        echo "Hit! $ip : $hostname : $hostGroup\n";
    } else {
        $hostGroup = substr($hostname, 0,2);
        echo "Miss! $ip : $hostname : $hostGroup\n";
    }
}

Miss! 10.1.40.1 : Z : Z
Hit! 10.1.41.1 : Z : B
Hit! 10.1.1.1 : Z : C
Miss! 10.1.40.1 : Z : Z
Hit! 10.9.1.1 : Z : C

Thanks!

-- 
Paul Halliday
http://www.pintumbler.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux