[PHP-JS] transformer tableau associatif php en tableau associatif Javascript
Bonjour,
J'ai trouv� la fonction ci-dessous permettant de transformer un tableau php en tableau javascript.
Elle marche tr�s bien, mais elle ne marche pas pour les tableaux associatifs...
Comment faire pour l'adapter aux tableaux associatifs?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
function construisTableauJS($tableauPHP, $nomTableauJS){
echo $nomTableauJS." = new Array();";
for($i = 0; $i < count($tableauPHP); $i++){
if(!is_array($tableauPHP[$i])){
echo $nomTableauJS."[".$i."] = '".$tableauPHP[$i]."';";
}
else{
construisTableauJS($tableauPHP[$i], $nomTableauJS."[".$i."]");
}
}
return;
} |
Merci d'avance.