如何从给定的CIDR获取IP范围

I want to get all IPs in the given subnet mask into an array using PHP. Below is the code which executes fine in my XAMPP server , but the same code when I am trying to execute on live Server it gives no error and no out put.

$cidrArray = array("1.1.1.1/24","2.2.2.2/24","3.3.3.3/24");
$countCIDRarrayLength = count($cidrArray);
for($i=0;$i<$countCIDRarrayLength;$i++){
        $arrayCIDRwise = explode('/',$cidrArray[$i]);
        $bin = '';
for($j=1;$j<=32;$j++) {
    $bin .= $arrayCIDRwise[1] >= $j ? '1' : '0';
}

  $arrayCIDRwise[1] = bindec($bin);
   $ip = ip2long($arrayCIDRwise[0]);
   $nm = ip2long($arrayCIDRwise[1]);
   $nw = ($ip & $nm);
   $bc = $nw | (~$nm);
for($zm=1;($nw + $zm)<=($bc - 1);$zm++)
    {
    $all_ipArrray[] = long2ip($nw + $zm).  "<br/>";

    }
}

I got snippet of code from "http://php.net/manual/en/function.ip2long.php", over which I had built my logic to get all IPs of the netmask in a single array.

I used the snippet code but unable to understand meaning of below mentioned:

  • $nw = ($ip & $nm);
  • $bc = $nw | (~$nm);

Though versions of PHP are same on Server and on local server XAMPP. The IP ranges I had defined above are dummy ranges of actual IPs.