PHP array conversion code

Source: Internet
Author: User

When you actually use PHP code, you mayThe following code converts PHP Arrays:

 
  1. <? Php
  2. Class arrayiconv
  3. {
  4. Static protected $ in;
  5. Static protected $ out;
  6. /**
  7. * Static method. This method inputs an array and returns an array.
  8. *
  9. * @ Param unknown_type $ array input array
  10. * @ Param unknown_type $ encoding of the input Array
  11. * @ Param unknown_type $ out returns the array encoding.
  12. * @ Return unknown returned array
  13. */
  14. Static public function Conversion ($ array, $ in, $ out)
  15. {
  16. Self: $In= $ In;
  17. Self: $Out= $ Out;
  18. Return self: arraymyicov ($ array );
  19. }
  20. /**
  21. * Internal method, cyclic Array
  22. *
  23. * @ Param unknown_type $ array
  24. * @ Return unknown
  25. */
  26. Static private function arraymyicov ($ array)
  27. {
  28. Foreach ($ array as $Key=>$ Value)
  29. {
  30. $Key=Self: Myiconv ($ key );
  31. If (! Is_array ($ value )){
  32. $Value=Self: Myiconv ($ value );
  33. } Else {
  34. $Value=Self: Arraymyicov ($ value );
  35. }
  36. $ Temparray [$ key] = $ value;
  37. }
  38. Return $ temparray;
  39. }
  40. /**
  41. * Replace array Encoding
  42. *
  43. * @ Param unknown_type $ str
  44. * @ Return unknown
  45. */
  46. Static private function myiconv ($ str)
  47. {
  48. Return iconv (self ::$ in, self ::$ out, $ str );
  49. }
  50. }
  51. $B=Array("Test" =>Array ("test" =>"Test", "test" =>"Test", "test" =>Array ("test" =>"Test"), "fasdf" =>"Test", "test" =>"Test ");
  52. $A=Arrayiconv: Conversion ($ B, "UTF-8", "gb2312 ");
  53. Print_r ($ );
  54. ?>

The above code is the specific implementation of PHP array conversion, and I hope it will be helpful to friends.


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.