3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $time_variant = array( 'group_a' => array( '0' => array( 'id_variant' => 122, 'name' => '3 hour 30 min', 'time' => 12600 ), '1' => array( 'id_variant' => 173, 'name' => '3 hour', 'time' => 10800 ), '2' => array( 'id_variant' => 271, 'name' => '1 hour', 'time' => 3600 ), ), 'group_b' => array( '0' => array( 'id_variant' => 107, 'name' => '1 hour 30 min', 'time' => 5400 ), '1' => array( 'id_variant' => 321, 'name' => '3 hour', 'time' => 10800 ), ), 'group_c' => array( '0' => array( 'id_variant' => 28, 'name' => '1 hour', 'time' => 3600 ), '1' => array( 'id_variant' => 98, 'name' => '3 hour', 'time' => 10800 ), '2' => array( 'id_variant' => 157, 'name' => '2 hour', 'time' => 7200 ), '3' => array( 'id_variant' => 158, 'name' => '1 hour 30 min', 'time' => 5400 ), ), ); $groupsCount = count( $time_variant ); foreach( $time_variant as $groupId => $groupArray ) { foreach( $groupArray as $groupChildId => $groupChildArray ) { $timeCountsArray[$groupChildArray['time']][$groupId] = $groupChildId; } } foreach( $timeCountsArray as $time => $groupIdsArray ) { if( count( $groupIdsArray ) >= $groupsCount ) { foreach( $groupIdsArray as $groupId => $groupChildId ) { $result[] = $time_variant[$groupId][$groupChildId]; } break; } } var_dump( $result );
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { [0]=> array(3) { ["id_variant"]=> int(173) ["name"]=> string(6) "3 hour" ["time"]=> int(10800) } [1]=> array(3) { ["id_variant"]=> int(321) ["name"]=> string(6) "3 hour" ["time"]=> int(10800) } [2]=> array(3) { ["id_variant"]=> int(98) ["name"]=> string(6) "3 hour" ["time"]=> int(10800) } }