note 55713 added to ref.array

From: Date: Thu, 11 Aug 2005 11:35:18 +0000
Subject: note 55713 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-93419@lists.php.net to get a copy of this message
in response to: Domenic Denicola I reworked your function a bit and thought i just as well could post it. Below is the cleaner version, just cut and paste ;) The third parameter is of little use to the coder, unless javascript declaration of variables changes at some point in the future - who knows. Only minor point is the added parameter which probably gets copied every recursive call with an empty value, though i don't know the exact ways how php handles recursion internally. Most of the time php is pretty smart when optimizing code and an empty string shouldn't take much memory anyway :) <?php function phpArrayToJsArray($name,$array,$prePend='var ') { if (is_array($array)) { // Array recursion $result = $name.' = new Array();'."\n"; foreach ($array as $key => $value) { $result .= phpArrayToJsArray($name.'["'.$key.'"]',$value,''); } } else { // Base case of recursion $result = $name.' = "'.$array.'";'."\n"; } return $prePend.$result; } ?> ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55713 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55713&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55713&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93419) next »