title: PHP - How to use config file variables in a function's array?
body: <p>I could not find an example of what I'm trying to accomplish. I guess I don't know the proper search words to use. I have a working script but I want to make it more flexible by adding a main, admin editable config file.</p>
  <p>I have the following function:</p>
  <pre><code>    function ip_is_mobile($ip) {
          $pri_addrs = array(                 
              '66.87.0.0-66.87.255.255',  // Sprint mobile
              '174.192.0.0-174.255.255.255'   // Verizon mobile
          );
      
          $long_ip = ip2long($ip);
      
          if($long_ip != -1) {
  
              foreach($pri_addrs AS $pri_addr) {
                  list($start, $end) = explode('-', $pri_addr);
  
                  // IF IS a mobile IP
                  if($long_ip &gt;= ip2long($start) &amp;&amp; $long_ip &lt;= ip2long($end))
                      return true;
              }
          }
          return false;
      }
  </code></pre>
  <p>I would like to replace the hard-coded IP address ranges, in the function, with variables or definitions which will be set in the main config file so that the config file has something similar to the following:</p>
  <pre><code>// Mobile IP address ranges. Add as many as needed.
  $MobileIPs['0']=&quot;66.87.0.0-66.87.255.255&quot;;
  $MobileIPs['1']=&quot;174.192.0.0-174.255.255.255&quot;;
  $MobileIPs['2']=&quot;85.110.50.0/24&quot;;
  </code></pre>
  <p>My goal is to give the admin an easy to read and understand way of adding as many IP address ranges as necessary (probably 20 max). I'm not opposed to totally rewriting the function if there is a better, more efficient way. In addition to IP ranges, it would be advantageous if CIDR's could also be specified; as indicated in the last code line above.</p>
  <p>What edits do I need to make to the function and what would the corresponding lines in the main config file be so that the user can add any number of ranges or CIDR's?</p>