note 89521 modified in function.json-encode by thiago

From: Date: Thu, 12 Mar 2009 12:49:28 +0000
Subject: note 89521 modified in function.json-encode by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151768@lists.php.net to get a copy of this message
<?php #json_encode php 5.2 << function JSON_print($result, $child = false) { foreach($result as $key => $val) { $is_child = 0; if(is_array($val)){ $AjaxReturn[] = JSON_print($val,true); $is_child++;} else $AjaxReturn[] = '\'' . $key . '\' : \'' . $val.'\''; } $return_json = $is_child > 0? '['.implode(', ',$AjaxReturn).']' : '{'.implode(', ',$AjaxReturn).'}'; if($child) return $return_json; else print $return_json; exit; } ?> --was-- #json_encode php 5.2 << function JSON_print($result, $child = false) { foreach($result as $key => $val) { $is_child = 0; if(is_array($val)){ $AjaxReturn[] = JSON_print($val,true); $is_child++;} else $AjaxReturn[] = '\'' . $key . '\' : \'' . $val.'\''; } $return_json = $is_child > 0? '['.implode(', ',$AjaxReturn).']' : '{'.implode(', ',$AjaxReturn).'}'; if($child) return $return_json; else print $return_json; exit; } http://php.net/manual/en/function.json-encode.php

« previous php.notes (#151768) next »