[array] Présence dans un tableau associatif ET multidimensionnel

Résolu/Fermé
Miimidedel Messages postés 345 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 5 juin 2019 - 4 févr. 2014 à 10:37
Miimidedel Messages postés 345 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 5 juin 2019 - 4 févr. 2014 à 15:24
Hello les gens !

Je m'arrache les cheveux sur un tableau.. !

Je voudrais pouvoir vérifier si une "combinaison" d'éléments appartient à un tableau multidimensionnel lui-même présent dans un tableau associatif..

Le tableau à parcourir :

$existingCategoryAttributesNames[] = array('attributeName' => $existingAttributeOverridedAttribute->getAttribute()->getName(),
'categoryName' => $existingCategory->getName(),
'categoryAttribute' => $existingAttributeOverridedAttribute);

Je voudrais tester si une combinaison attributeName / categoryName existe dans le tableau !

Comment faire ? Car si elle existe je la modifie, si elle n'existe pas j'ajoute qq chose dans ma BDD. Avec mon code actuel (combinaison de foreach et de if(in array()) ça compare chaque ligne... Si la combinaison ne correspond pas au 1er élément il ajoute, même si elle correspond au 5ème..


Une idée ? Je craque avec cet arrayception T_T...

Je vous remercie d'avance !

1 réponse

Miimidedel Messages postés 345 Date d'inscription mercredi 4 août 2010 Statut Membre Dernière intervention 5 juin 2019 71
4 févr. 2014 à 15:24
Bon, j'ai trouvé une solution, en espérant que ça pourra en aider d'autres :

foreach ($existingCategoryAttributesNames as $key2 => $existingCategoryAttributesName) {

if ($existingCategoryAttributesNames[$key2]['attributeName'] == $key && $existingCategoryAttributesNames[$key2]['categoryName'] == $category) {
$existingCategoryAttributeMine = $existingCategoryAttributesNames[$key2]['categoryAttribute'];

break;
}
}
0