URL: https://www.overclockers.at/coding-stuff/php_array_zu_javascript_array_152827/page_1 - zur Vollversion wechseln!
Hallo Allerseits,
folgendes Problem: Ich habe aus einer Datenbankabfrage ein 2Dimensionales Array erstellt.
$array[x][x]
$array[0][0]
$array[0][1]
$array[0][2]
....
Dieses Array möchte ich nun von PHP nach Javascript importieren (um bei einem dynamischen Formular den Seitenreload zu ersparen, speichere ich sämtliche notwendige Daten sofort in ein JS Array).
Folgenden Code habe ich bisher:
Code:/* PHP-ARRAY in JAVASCRIPT ARRAY portieren */ echo "<script type=\"text/javascript\">\n"; echo "<!--\n"; echo "var test = new Array();\n"; foreach ($bla as $key => $value) { $subArrayLength = sizeof($value); for($cnt=0; $cnt < $subArrayLength; $cnt++) { echo "test['$key']['$cnt'] = '$value[$cnt]';\n"; } } echo "alert(test.length);\n"; echo "document.write(test.join('.'));\n"; echo "//-->\n"; echo "</script>\n";
m.w. kann php keine arrays in echo ""
versuch mal:
echo "test['$key']['$cnt'] = '" . $value[$cnt] . "';\n";
Wie sieht der generierte code aus?
Was für ein JS-Error kommt?
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2026