array syntax or grammar in javascript vs php
Posted: Fri Mar 10, 2017 6:02 am
<?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>
//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>