J'essaie de rechercher un tableau multidimensionnel, mais la recherche renvoie uniquement la première occurrence.Recherche tableau multidimensionnel retournant plusieurs résultats
J'ai un tableau à plusieurs dimensions $planned_housek
:
Array
(
[0] => Array
(
[id] => 14
[title] => Titel 10
[ruletext] => Regel 10
[room] => 101
[roomid] => 43
)
[1] => Array
(
[id] => 14
[title] => Titel 10
[ruletext] => Regel 10
[room] => 102
[roomid] => 42
)
[2] => Array
(
[id] => 14
[title] => Titel 10
[ruletext] => Regel 10
[room] => 103
[roomid] => 41
)
[3] => Array
(
[id] => 14
[title] => Titel 10
[ruletext] => Regel 10
[room] => 104
[roomid] => 44
)
[4] => Array
(
[id] => 14
[title] => Titel 10
[ruletext] => Regel 10
[room] => 105
[roomid] => 45
)
[5] => Array
(
[id] => 7
[title] => TItel 3
[ruletext] => Regel 3
[room] => 101
[roomid] => 43
)
[6] => Array
(
[id] => 13
[title] => Titel 9
[ruletext] => Regel 9
[room] => 101
[roomid] => 43
)
)
Quand je recherche avec:
$planned_tasks = array_search($bkng_room, array_column($planned_housek, 'roomid'));
Il retourne la première occurrence de la $bkng_room
.
Dois-je utiliser un for/foreach
pour obtenir un tableau de résultats? Ou y a-t-il une solution plus élégante (PHP 5.5)? J'ai trouvé cette question, mais la réponse ne semble pas la solution la plus élégante: How to search a multidimensional array to return multiple keys. Ni fait celui-ci: Search multidimensional array for value and return new array
Dans la documentation sur array_search
je trouve:
Si l'aiguille se trouve dans botte de foin plus d'une fois, la première clé correspondant est retourné. Pour renvoyer les clés pour toutes les valeurs correspondantes, utilisez array_keys() avec le paramètre facultatif search_value à la place.
Mais je ne suis pas sûr comment implémenter cela dans mon code.