search - Which PHP data structure for quick single VALUE lookups with unique KEY? -


i have dynamically generated list of url's our internal network. each url, want to:

  1. find ip of url.
  2. compare ip list of ip's , associated server.
  3. return server associated ip.

the ip of course unique in list of ip's, there recommended way store list of ip values can supply ip (key) , associated server (value)?

i've looked @ multidimensional arrays, or brute force -- create array each individual server's ip list -- seems inefficient.

here php want have (psuedo):

$ipserverlist = array(0 => array(ip=>1.2.3.4,server=>"server1"),        1 => array(ip=>2.1.3.4,server=>"server2"),        2 => array(ip=>3.1.3.3,server=>"server1"));  getserver("url1.mycoolurl.com");  function getserver($url) {     $ip = gethostbyname($url); "search $ipserverlist $ip , return 'server' value"     //   } 

are there specific ways should storing ip/server list? recommended built in php functions search? appreciated!

i'm not seeing obvious reason avoiding associative arrays:

$ipserverlist = array(   '1.2.3.4' => "server1",   '2.1.3.4' => "server2",   '3.1.3.3' => "server1", ); 

arrays in php double has hashs/maps/dictionaries, depending on you're used calling them. point is, can use unique string/number array index, , since seem have 1-to-1 mapping of ips server names, seems ideal.

i don't think you're going find faster way in php access data, , can't beat simplicity:

 if (array_key_exists($ipserverlist, '192.168.1.1')) {    echo $ipserverlist['192.168.1.1'];  } 

the php manual on arrays useful.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -