note 103303 added to book.array

From: Date: Wed, 06 Apr 2011 11:37:35 +0000
Subject: note 103303 added to book.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-178549@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 212.17.83.249 ---- Manual Page -- http://www.php.net/manual/en/book.array.php Edit -- https://master.php.net/note/edit/103303 Del: integrated -- https://master.php.net/note/delete/103303/integrated Del: useless -- https://master.php.net/note/delete/103303/useless Del: bad code -- https://master.php.net/note/delete/103303/bad+code Del: spam -- https://master.php.net/note/delete/103303/spam Del: non-english -- https://master.php.net/note/delete/103303/non-english Del: in docs -- https://master.php.net/note/delete/103303/in+docs Del: other reasons-- https://master.php.net/note/delete/103303 Reject -- https://master.php.net/note/reject/103303 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178549) next »