|
|
|
|
Bjr Martin
Voici un ex : <html>
<head>
<script type="text/javascript">
<!--
<?php
$tableau = array();
$tableau[0][0] = 0;
$tableau[0][1] = 1;
$tableau[0][2] = 2;
$tableau[1][0] = 'Item 1-0';
$tableau[1][1] = 'Item 1-1';
$tableau[1][2] = 'Item 1-2';
$tableau[2][0] = 'Item 2-0';
$tableau[2][1] = 'Item 2-1';
$tableau[2][2] = 'Item 2-2';
// Déclaration du tableau JavaScript
$tableau_JS="Tableau";
printf("%s = new Array();\n",$tableau_JS);
foreach($tableau as $keyItems => $valueItems)
{
printf("%s[%s]= new Array();\n",$tableau_JS, $keyItems);
foreach($valueItems as $keyItem => $valueItem)
{
printf("%s[%s][%s] =%s;\n",$tableau_JS, $keyItems, $keyItem,
is_string($valueItem) ? "\"".addslashes($valueItem)."\"" : $valueItem);
}
}
?>
// Fonction pour récuperer le contenu du tableau sous forme de texte
function getText()
{
var txt = "";
for (var i=0; i < Tableau.length; i++)
{
for (var j=0; j < Tableau[i].length; j++)
{
txt = txt+ 'Tableau['+i+']['+j+']='+Tableau[i][j]+'\n';
}
}
return txt;
}
//-->
</script>
</head>
<body onload="alert(getText())">
</body>
</html>
Remarques : tu n'es pas onligé d'utiliser l'instruction foreach PHP un for classique peut convenir cepandant elle est bien pratique ... l'événement onload ne sert que pour le test tu peux le supprimer ainsi que le fct getText() J'ai supposé ici que le tableau contenait à la fois des chaînes de caractères et des nombres. Qu'entends-tu par un tableau graphique JavaScript ???? PhP -- PhP |
| 23/08 12h40 | javascript vers php et php vers javascript | Programmation | 23/08 13h24 | 4 |
| 28/06 16h50 | de [PHP] vers [javascript] | Programmation | 29/06 05h27 | 6 |
| 08/08 11h38 | ProblèmeS passage PHP4 vers PHP5 | Webmastering | 09/08 00h41 | 4 |
| 18/07 17h32 | php et javascript: passation de variable | Programmation | 18/07 19h29 | 5 |