Passer un tableau associatif php vers JS
Bonjour j'ai un tableau php créer dynamiquement et je souhaite l'envoyer vers javascript
tout d'abord voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<script>
function test(tb){
}
</script>
<?php
function markt(){
$tchem = array() ;
$tnom = array () ;
while( $monwhile ){
if( $macondition ){
$chem = $madonnee ;
$nc = $madonneeb ;
array_push($tchem,$chem) ;
array_push($tnom,$nc) ;
$tf = array_combine($tchem,$tnom) ;
}
}
$enc = json_encode($tf) ;
echo '<script> test(\''. $enc .'\') </script>' ;
} //fin function
markt() ;
?> |
j'ai bien mis le tableau en php voulu en JSON , et je l'ai mis en paramètres de ma fonction JS :
Code:
1 2 3 4 5 6
|
$enc = json_encode($tf) ;
echo '<script> test(\''. $enc .'\') </script>' ; |
et je pense qu'il est envoyer correctement car quand je fais un alert ,
l'alert affiche mon array
le souci est que j'arrive pas à faire un truc du genre :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
<script>
function test(tb){
alert(tb) // J'ai mon Array qui s'affiche
// je souhaite faire un truc du genre :
/*
foreach( $tf as $x => $y ){
}
*/
// MAIS EN JAVASCRIPT
}
</script> |
comment faire ? merci