PHP returns a JSON array

Source: Internet
Author: User

1. Back end

//dealing with problems with JSON arrays in ChinesefunctionArrayrecursive (&$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--;}

// returns a JSON array directly function JSON ($array) {    arrayrecursive ($arraytrue);     $json = Json_encode ($array);     return UrlDecode ($json);}

// called $data Array (); $data [' Success ']= "false"; $data [' Message ']= ' username does not exist, please re-enter'        ; Echo JSON ($data);

2. Front End

$.post ("Ajax.php?mod=member&code=check_user_exist", {username:username},function(data) {             var json=$.parsejson (data);             if (json.success) {                alert (json.success);                          }else{                alert (json.success);                     }        });

PHP returns a JSON array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.