array syntax or grammar in javascript vs php

notes and quirk solutions found over time
Post Reply
darknkreepy3#
Site Admin
Posts: 254
Joined: Tue Oct 27, 2009 9:33 pm

array syntax or grammar in javascript vs php

Post by darknkreepy3# »

<?php
//a new array in php uses ( and )
$dancerArr=Array("esmerelda","chianna","cream");
echo count($dancerArr);
echo implode(",",$dancerArr);
?>

<script>
/*
if it were created in javascript, it would be created with [ and ]
and there is no array or Array used to define the array itself

var dancerArr=["esmerelda","chianna,","cream"];

and if a single number is used in the [ ] as
var dancerArr=[3];
that creates a 3 node array, not a single node with the number 3 or string '3' in node 0.
*/

var dancerArrStr="<?php echo implode(",",$dancerArr);?>";
var dancerArr=dancerArrStr.split(",");
alert(dancerArrStr);
alert(dancerArr[1]);
</script>
Post Reply