note 103676 deleted from function.json-encode by danbrown

From: Date: Wed, 27 Apr 2011 18:27:49 +0000
Subject: note 103676 deleted from function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179205@lists.php.net to get a copy of this message
Note Submitter: marcoslhc at gmail dot com ---- The function dave wrote works perfectly fine except when the function returns the encoded value has to decrease the recursion depth by one function utf8json($inArray) { static $depth = 0; /* our return object */ $newArray = array(); /* safety recursion limit */ $depth ++; if($depth >= '30') { return false; } /* step through inArray */ foreach($inArray as $key=>$val) { if(is_array($val)) { /* recurse on array elements */ $newArray[$key] = utf8json($val); } else { /* encode string values */ $newArray[$key] = utf8_encode($val); /*the depth is one level up */ if($depth>0) { $depth --; } } } /* return utf8 encoded array */ return $newArray; }

« previous php.notes (#179205) next »