How PHP recursively converts null in an array to an empty string "method

Source: Internet
Author: User

In some interface calls, directly querying the database out of the field may be a null field, but for the sake of a simple front-end judgment, you need to convert null to an empty string ', this time it needs to be recursive way. The direct code is as follows:


//recursively converts an array or string NULL to a null ' string Public function_unsetnull ($arr){ if($arr!==NULL){ if(Is_array($arr)){ if(!Empty($arr)){ foreach($arr as $key=$value){ if($value===NULL){ $arr[$key] = "; }Else{ $arr[$key] =$this->_unsetnull ($value);//recursion to execute again } } }Else{$arr= ' '; } }Else{ if($arr===NULL){$arr= "; }//note three equals sign } }Else{$arr= ' '; } return $arr; }

How PHP recursively converts null in an array to an empty string "method

Related Article

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.