On Wed, Oct 24, 2012 at 2:40 PM, Samuel Lopes Grigolato <samuel.grigolato@xxxxxxxxx> wrote: > Could you try changing this: > > if($groupTest != FALSE) { > > to this: > > if($groupTest !== FALSE) { > > ? Hah. Perfect! Thanks. > > -----Mensagem original----- > De: Paul Halliday [mailto:paul.halliday@xxxxxxxxx] > Enviada em: quarta-feira, 24 de outubro de 2012 15:38 > Para: PHP-General > Assunto: Array help. > > 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 > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php