3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function ipv4Breakout ($ip_address, $ip_nmask) { $hosts = array(); //convert ip addresses to long form $ip_address_long = ip2long($ip_address); $ip_nmask_long = ip2long($ip_nmask); //caculate network address $ip_net = $ip_address_long & $ip_nmask_long; //caculate first usable address $ip_host_first = ((~$ip_nmask_long) & $ip_address_long); $ip_first = ($ip_address_long ^ $ip_host_first) + 1; //caculate last usable address $ip_broadcast_invert = ~$ip_nmask_long; $ip_last = ($ip_address_long | $ip_broadcast_invert) - 1; //caculate broadcast address $ip_broadcast = $ip_address_long | $ip_broadcast_invert; foreach (range($ip_first, $ip_last) as $ip) { array_push($hosts, $ip); } $block_info = array(array("network" => "$ip_net"), array("first_host" => "$ip_first"), array("last_host" => "$ip_last"), array("broadcast" => "$ip_broadcast"), $hosts); return $block_info; } print_r(ipv4Breakout ('96.4.3.0', '255.255.255.0'));
based on Yestf
Output for 7.0.0 - 7.2.0
Warning: range(): The supplied range exceeds the maximum array size: start=-2684091394 end=1610875649 in /in/9LoFN on line 23 Warning: Invalid argument supplied for foreach() in /in/9LoFN on line 23 Array ( [0] => Array ( [network] => 1610875648 ) [1] => Array ( [first_host] => 1610875649 ) [2] => Array ( [last_host] => -2684091394 ) [3] => Array ( [broadcast] => -2684091393 ) [4] => Array ( ) )
Output for 5.3.19 - 5.6.28
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/9LoFN on line 23
Process exited with code 255.