3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $alist = array ( array('Effective Supervisory', '18/07/1992', '19/07/1992'), array('Effective Supervisory', '16/08/1992', '16/08/1992'), array('Effective Supervisory', '19/08/1992', '19/08/1992'), array('Seven Habits', '19/09/1992', '19/09/1992'), array('Seven Habits', '20/09/1992', '20/09/1992'), array('Effective Supervisory', '29/08/1992', '29/08/1992'), ); function searchForKeyValues($searchVal, $array) { $keys = array(); $n = 0; foreach ($array as $key => $val) { if ($val[0] === $searchVal) { $keys[$n++] = $key; } } return $keys; } function getAllKeys($array, $arrayCol) { $keys = array(); $n = 0; foreach ($array as $key => $val) { $keys[$n++] = $val[$arrayCol]; } return array_unique($keys); } $allKeys = getAllKeys($alist, 0); var_dump($allKeys); foreach ($allKeys as $searchVal) { echo "Searching for '$searchVal' :\n"; var_dump(searchForKeyValues($searchVal, $alist)); } ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(2) { [0]=> string(21) "Effective Supervisory" [3]=> string(12) "Seven Habits" } Searching for 'Effective Supervisory' : array(4) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(5) } Searching for 'Seven Habits' : array(2) { [0]=> int(3) [1]=> int(4) }