Home  >  Article  >  php教程  >  迅速掌握PHP JSON加密函数运用技巧

迅速掌握PHP JSON加密函数运用技巧

WBOY
WBOYOriginal
2016-06-13 11:09:551219browse

以下为PHP JSON加密函数的具体应用:

  1. function php_json_encode($arr)   
  2. {   
  3. $json_str = "";   
  4. if(is_array($arr))   
  5. {   
  6. $pure_array = true;   
  7. $array_length = count($arr);   
  8. for($i=0;$i$array_length;$i++)   
  9. {   
  10. if(! isset($arr[$i]))   
  11. {   
  12. $pure_array = false;   
  13. break;   
  14. }   
  15. }   
  16. if($pure_array)   
  17. {   
  18. $json_str ="[";   
  19. $temp = array();   
  20. for($i=0;$i$array_length;$i++)   
  21. {   
  22. $temp[] = sprintf("%s", php_json_encode($arr[$i]));   
  23. }   
  24. $json_str .implode(",",$temp);   
  25. $json_str .="]";   
  26. }   
  27. else   
  28. {   
  29. $json_str ="{";   
  30. $temp = array();   
  31. foreach($arr as $key => $value)   
  32. {   
  33. $temp[] = sprintf(""%s":%s", $key, php_json_encode($value));   
  34. }   
  35. $json_str .implode(",",$temp);   
  36. $json_str .="}";   
  37. }   
  38. }   
  39. else   
  40. {   
  41. if(is_string($arr))   
  42. {   
  43. $json_str = """. json_encode_string($arr) . """;   
  44. }   
  45. else if(is_numeric($arr))   
  46. {   
  47. $json_str = $arr;   
  48. }   
  49. else   
  50. {   
  51. $json_str = """. json_encode_string($arr) . """;   
  52. }   
  53. }   
  54. return $json_str;   
  55. }  

希望通过上面这段代码的演示,大家能够充分掌握PHP JSON加密函数的用法,帮助自己完善代码编程。


Statement:
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