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; } } $result = array(); foreach( $timeCountsArray as $time => $groupIdsArray ) { if( $groupsCount > count( $groupIdsArray ) ) continue; foreach( $groupIdsArray as $groupId => $groupChildId ) { $result[$time_variant[$groupId][$groupChildId]['id_variant']] = $time_variant[$groupId][$groupChildId]; // If you need only one result , uncomment the below break break; } // If more than 1 time could have variants , comment out below break to get them all break; } ksort( $result ); print_r( $result );
Output for 5.4.0 - 5.6.28
Warning: Illegal offset type in /in/ifik8 on line 7 Warning: Illegal offset type in /in/ifik8 on line 8 Warning: Illegal offset type in /in/ifik8 on line 10 Warning: Illegal offset type in /in/ifik8 on line 10 Warning: Illegal offset type in /in/ifik8 on line 12 Warning: Illegal offset type in /in/ifik8 on line 13 Warning: Illegal offset type in /in/ifik8 on line 15 Warning: Illegal offset type in /in/ifik8 on line 15 Warning: Illegal offset type in /in/ifik8 on line 17 Warning: Illegal offset type in /in/ifik8 on line 18 Warning: Illegal offset type in /in/ifik8 on line 20 Warning: Illegal offset type in /in/ifik8 on line 20 Warning: Illegal offset type in /in/ifik8 on line 24 Warning: Illegal offset type in /in/ifik8 on line 25 Warning: Illegal offset type in /in/ifik8 on line 27 Warning: Illegal offset type in /in/ifik8 on line 27 Warning: Illegal offset type in /in/ifik8 on line 29 Warning: Illegal offset type in /in/ifik8 on line 30 Warning: Illegal offset type in /in/ifik8 on line 32 Warning: Illegal offset type in /in/ifik8 on line 32 Warning: Illegal offset type in /in/ifik8 on line 36 Warning: Illegal offset type in /in/ifik8 on line 37 Warning: Illegal offset type in /in/ifik8 on line 39 Warning: Illegal offset type in /in/ifik8 on line 39 Warning: Illegal offset type in /in/ifik8 on line 41 Warning: Illegal offset type in /in/ifik8 on line 42 Warning: Illegal offset type in /in/ifik8 on line 44 Warning: Illegal offset type in /in/ifik8 on line 44 Warning: Illegal offset type in /in/ifik8 on line 46 Warning: Illegal offset type in /in/ifik8 on line 47 Warning: Illegal offset type in /in/ifik8 on line 49 Warning: Illegal offset type in /in/ifik8 on line 49 Warning: Illegal offset type in /in/ifik8 on line 51 Warning: Illegal offset type in /in/ifik8 on line 52 Warning: Illegal offset type in /in/ifik8 on line 54 Warning: Illegal offset type in /in/ifik8 on line 54 Notice: Undefined variable: timeCountsArray in /in/ifik8 on line 70 Warning: Invalid argument supplied for foreach() in /in/ifik8 on line 70 Array ( )
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected '[', expecting ')' in /in/ifik8 on line 6
Process exited with code 255.