PHPå®ä¾ä»£ç :模仿ç¾åº¦æç´¢æ¶è¾å ¥å 容带æ示
$aName = array("çæ","çç","ç祥","ä½æ¦æ","ä½ç¿","ä½å¥½","??©¬å
´","??©¬ææ ","å¼ ç¸","å¼ ç¥¥");
$aId = array(88801,11144,2345,9023,12415,88021,11145,2344,11145,0376);
foreach($aName as $k =>$val)
{
$json[$k] = array(
'id' => $aId[$k],
'name' => $val
);
}
/**************************************************************
*
* 使ç??ç¹å®function对æ??ç»ä¸ææå
ç´ åå??ç
* @param string &$array ??¦å??ççå符串
* @param string $function ??¦æ?쨨¡çå½æ??
* @return boolean $apply_to_keys_also æ¯å¦ä¹åºç??å??keyä¸
* @access public
*
*************************************************************/
function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
{
static $recursive_counter = 0;
if (++$recursive_counter > 1000) {
die('possible deep recursion attack');
}
foreach ($array as $key => $value) {
if (is_array($value)) {
arrayRecursive($array[$key], $function, $apply_to_keys_also);
} else {
$array[$key] = $function($value);
}
if ($apply_to_keys_also && is_string($key)) {
$new_key = $function($key);
if ($new_key != $key) {
$array[$new_key] = $array[$key];
unset($array[$key]);
}
}
}
$recursive_counter--;
}
/**************************************************************
*
* å??æ??ç»??½¬æ¢ä¸ºJSONå符串ï¼å
¼å®¹ä¸æï¼
* @param array $array ??¦??½¬æ¢çæ??ç»
* @return string ??½¬æ¢å¾å??çjsonå符串
* @access public
*
*************************************************************/
function JSON($array) {
arrayRecursive($array, 'urlencode', true);
$json = json_encode($array);
return urldecode($json);
}
?>
??¾å ¥æµ??¯ï¼ |