J'ai un tableau en session :
$_SESSION[arr][]=array('ref' => $ref,'designation' => $designation)
J'aimerais tester la présence d'une variable $ref dans ce tableau
Comment faire ?
in_array($ref,$_SESSION['ar'] )
Grand merciin_array($ref,$_SESSION['ar'] )
Grand merci
BingoComment faire ?in_array($ref,$_SESSION['ar'] )
if(isset($_SESSION['arr']) && in_array($ref, $_SESSION['arr'])){echo 'valeur trouvee';}
var_dump($_SESSION);
tu obtient quoi ?
$_SESSION[arr][]=array(...)
d'où mon interrogation pour savoir si le in_array irait jusque là pour retourner un résultat ou s'il s'arrêterais au premier niveau ne contenant que des tableaux et retournant qu'il ne l'a pas trouvé...
$_SESSION[$arr]["ref"] = $ref;
$_SESSION[$arr]["designation"] = $designation;
soit tu fait
$_SESSION[$arr] = array('ref' => $ref,'designation' => $designation);
Mais pas les 2, sinon tu as une dimension en trop $_SESSION[$arr] = array('ref' => $ref,'designation' => $designation);
[/php]foreach( $_SESSION['devis'] as $v )
{
if($v['ref']==$ref){echo 'toto';}
}
if( $_SESSION['devis']['ref']==$ref){echo 'toto';}
//ou
if ( in_array($ref,$_SESSION['devis']) ){echo 'toto';}
// sachant que du coup il ira aussi regarder s'il trouve la valeur dans "designation"