3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function findNetworkWithIPAddress(array $payload, string $ipAddress): array { $network = array_values(array_filter($payload, function (array $networkInfo) use ($ipAddress) { $address = $networkInfo['address'] ?? ''; /** for PHP < 8.0 */ // return substr($address, 0, strlen($ipAddress)) === $ipAddress; /** for PHP >= 8.0 */ return str_starts_with($address, $ipAddress); })); return reset($network) ?: []; } $payload = [ [ ".id" => "*1", "address" => "10.9.4.109/24", "network" => "10.9.4.0", "interface" => "ether1", "actual-interface" => "ether1", "invalid" => false, "dynamic" => false, "disabled" => false, ], [ ".id" => "*2", "address" => "10.9.4.209/24", "network" => "10.9.4.0", "interface" => "ether2", "actual-interface" => "ether2", "invalid" => false, "dynamic" => false, "disabled" => false, ], ]; $network = findNetworkWithIPAddress($payload, '10.9.4.209'); $interfaceName = $network['interface'] ?? ''; var_dump($interfaceName);
Output for git.master, git.master_jit, rfc.property-hooks
string(6) "ether2"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.42 ms | 401 KiB | 8 Q