note 103303 deleted from book.array by peehaa
| From: | peehaa@php.net | Date: | Mon, 08 Jul 2013 21:17:25 +0000 |
| Subject: | note 103303 deleted from book.array by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195536@lists.php.net to get a copy of this message | ||
Note Submitter: fo dot q dot who at gmail dot com
----
Just another way to pass a multidimensional php array to a js array, but i think a cool one so I
decided to put this on here.
<?php
function array_print($item, $key, $array_name)
{
if(is_array($item)){
$array_name = $array_name."['".$key."']";
echo $array_name ."= Array();". "";
php_array_to_js_array($item, $array_name);
}else{
echo $array_name."['".$key."'] =
\"".$item."\";";
}
}
function php_array_to_js_array($array, $array_name){
array_walk($array, 'array_print', $array_name);
}
?>
<script type="text/javascript" defer="defer">
<?php
echo "js_array = Array();";
php_array_to_js_array($array, "js_array");
?>
</script>
there is not much to say about that, its simple and understandable, i think... if not just email me.
Have a nice day pplz !!
Patrick F.