[PHP] Recherche valeur dans tableau multidime

zebuel -  
 Alain42 -
Bonjour,

Comment puis je faire pour recherche une valeur dans un tableau(array) multidimension?
Pour un tableau à une dimension, je connais la fonction array_search, mais je ne connais pas celle pour un tableau à plusieurs dimensions.

Merci.
A voir également:

3 réponses

ELTONIO
 
If you wanna find a value in multidimensional array with array_search. You should do the following:

Use For-Each, that it solves your Problem!

Example:

$map = array( array( Name=>'Jordan' ),
array( Name=>'Oneal' )
);

<?php
$search_value = "Jordan";

foreach ($map as $key => $row)
{
foreach($row as $cell)
{
if ($cell == $search_value)
print $key;
}
}
?>
6
Alain42
 
Bonsoir,

si tu ne comprend pas l'anglais:

tableau a deux dimensions, tu parcours par une boucle la dimension 1 et a chaque fois par une boucle tu parcours la dimension 2

ex

$tabl_multi

foreach($tabl_multi as $ligne){
foreach($ligne as col){
//ton array_search sur $col
}
}

si plus de dimensions, tu imbriques d'autres boucles
5
docteurbill
 
soit un tableau $tab construit avec 2 colonnes "colonne1" et "colonne2"
print ( $tab ["colonne1"] [1] );
ou print ( $tab ["colonne2"] [6] );
ext ...
-8