Tuesday, 15 June 2010

Looping through an Array in Javascript from a PHP Array -



Looping through an Array in Javascript from a PHP Array -

i have array in php variable called: $tillarray

i want pass value javascript function , display alert each item in array.

here code:

<script type="text/javascript"> arrayfunction(<?= $tillarray ?>); </script>

here function code:

function arrayfunction(myarray) { (var = 0; < myarray.length; i++) { alert(myarray[i]); } }

the function displays "undefined" message.

can please have help working?

because can't that. you'd have create array loopable js turning array js can use. turn json, depends on how created array. if indexes numerical, json_encode turn js array , of 3 basic loops iterate on it. if associative array, turn js object , have utilize for-in loop.

arrayfunction(<?= json_encode($tillarray) ?>);

php javascript arrays alert

No comments:

Post a Comment