Est-il possible de placer une variable dans une clef :
$_SESSION[$variable] ? Je n'y suis arrivé ni avec les '' ni avec {} autour de la variable. Y a-t-il un moyen de contourner la chose?
Merci pour vos hints.
Version imprimable
Est-il possible de placer une variable dans une clef :
$_SESSION[$variable] ? Je n'y suis arrivé ni avec les '' ni avec {} autour de la variable. Y a-t-il un moyen de contourner la chose?
Merci pour vos hints.
Oui c'est possible
Code:
1
2
3
4
5
6
7
8
9 $animal = 'chien'; $_SESSION[$animal]['cri'] = 'ouaf'; $animal = 'chat'; $_SESSION[$animal]['cri'] = 'miaou'; echo $_SESSION['chat']['cri'] -> miaou
Merci, c'est amusant et convainquant!
Oui, ça marche, tant que la variable est un entier ou une chaîne, la clé étant la valeur de cette variable.
http://php.net/manual/en/language.types.array.php
Code:
1
2
3 array(key => value, ...) // key may only be an <a href="http://www.php.net/manual/en/language.types.integer.php" target="_blank">integer</a> or <a href="http://www.php.net/manual/en/language.types.string.php" target="_blank">string</a> // value may be any value of any type