string json_encode(mixed $variable)
<?php $array=array(5,1,7,2,8,3); $javascript=json_encode($array); echo "$javascript <br>"; echo "<script type='text/javascript'>var array=$javascript</script>"; //Returns a Javascript array: [5,1,7,2,8,3]
?>
<?php class example{ public hello="hola"; public bye="adios"; } $ex=new example(); echo $jsex=json_encode($ex); echo "<script type='text/javascript'>var example=$jsex;document.write(example.hello)</script>" //Returns: {"hello":"hola","bye":"adios"} ?>
mixed json_decode(string $javascript, [bool $associative_array])
<?php $js="[1,7,3,8,3]"; //Javascript array $phparray=json_decode($js); print_r $phparray; //Returns: Array ( [0] => 1 [1] => 7 [2] => 3 [3] => 8 [4] => 3 ) >