Hello people, I have a php script which calls a javascript function with a parameter. I am having trouble getting this parameter act as an array inside the javascript function:
php:
[CODE]
<? $array1 = ‘”apple”,”orange”,”banana”‘;
$array2 = ‘”corn”,”bean”,”beet”‘;
$arrays = $array1.’///’.$array2;
<script type=”text/javascript”>
jsfunc(‘<? echo $arrays;?>’);
</script>
js:
[CODE]
function jsfunc(arrays) {
array = arrays.split(“///”);
fruits = Array(array[0]);
vegs = Array(array[1]);
alert(fruits[0]); //outputs all the elements, instead of just “apple”
}
JS sees fruits and vegs as a string rather then an array, so if I try to output fruits[0]; it gives me the entire string rather then seeing it as an array and giving me the first element.
What am I doing wrong?