PHP array and object conversion small example

WBOY
Release: 2016-07-25 09:11:54
Original
852 people have browsed it

php array and object conversion

Example:

  1. //php object to array conversion
  2. private function objToArr($obj){
  3. if(!is_object($obj) && !is_array($obj)) {
  4. return $obj;
  5. }
  6. $arr = array();
  7. foreach($obj as $k => $v){
  8. $arr[$k] = $this->objToArr($v);
  9. }
  10. return $arr ;
  11. } // bbs.it-home.org
  12. //Simple implementation of json to php array conversion function
  13. private function simple_json_parser($json){
  14. $json = str_replace("{","",str_replace("} ","", $json));
  15. $jsonValue = explode(",", $json);
  16. $arr = array();
  17. foreach($jsonValue as $v){
  18. $jValue = explode(": ", $v);
  19. $arr[str_replace('"',"", $jValue[0])] = (str_replace('"', "", $jValue[1]));
  20. }
  21. return $ arr;
  22. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!