- print_r: documentation ( source)
<?php
$array = [
'1' => true,
['2' => false, '4' => true],
'3' => true
];
function findKeysWithTrueValues(array $array): array
{
$matches = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
foreach (findKeysWithTrueValues($value) as $match) {
$matches[] = $match;
}
} elseif ($value === true) {
$matches[] = $key;
}
}
return $matches;
}
print_r(findKeysWithTrueValues($array));