Quick mastery of PHP json cryptographic functions using _php Tutorial

Source: Internet
Author: User
Tags php json sprintf

The following are the specific applications of PHP JSON cryptographic functions:

  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. }

Hope that through the above code demonstration, you can fully grasp the PHP JSON cryptographic function usage, to help you improve code programming.


http://www.bkjia.com/PHPjc/446100.html www.bkjia.com true http://www.bkjia.com/PHPjc/446100.html techarticle The following is the specific application of the PHP JSON cryptographic function: Functionphp_json_encode ($arr) {$ json_str =; if (Is_array ($arr)) {$ pure_array = true; $ arra Y_length = count ($arr); for ($ i = 0 ...

  • 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.