- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- 'col2'
<?php
$a = [
"row1" => ["col1" => "value1"],
"row2" => ["col2" => "value2"],
"rowN" => ["colN" => "valueN"],
];
function getKeyOfFirstValue(array $haystack, $needle) {
foreach ($haystack as $row) {
foreach ($row as $key => $value) {
if ($value === $needle) {
return $key;
}
}
}
return null;
}
var_export(getKeyOfFirstValue($a, 'value2'));