3v4l.org

run code in 500+ PHP versions simultaneously
<?php $comps = [ [ 'c_id' => '123', 'status' => 'active' ], [ 'c_id' => '456', 'status' => 'destroyed' ], [ 'c_id' => '789', 'status' => 'active' ] ]; $rests = [ [ 'r_id' => 123, 'extra' => 'some extra info for r_id 123' ], [ 'r_id' => 456, 'extra' => 'some extra info for r_id 456' ] ]; var_export( array_uintersect( $comps, $rests, function($a, $b) { return [$a['c_id'] ?? $a['r_id'], ($a['status'] ?? 'active') === 'active'] <=> [$b['c_id'] ?? $b['r_id'], ($b['status'] ?? 'active') === 'active']; } ) );
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.21, 8.5.0 - 8.5.7
array ( 0 => array ( 'c_id' => '123', 'status' => 'active', ), )

preferences:
92.9 ms | 1263 KiB | 4 Q