Rumah  >  Artikel  >  php教程  >  PHP数组转换的具体代码编写介绍

PHP数组转换的具体代码编写介绍

WBOY
WBOYasal
2016-06-13 11:06:161011semak imbas

大家在实际使用PHP代码的时候也许对以下就是PHP数组转换具体的代码:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"></font></strong></span><span> ?php      </span></span></li>
<li class=""><span>class arrayiconv      </span></li>
<li class="alt"><span>{      </span></li>
<li class=""><span>static protected $in;      </span></li>
<li class="alt"><span>static protected $out;      </span></li>
<li class=""><span>/**     </span></li>
<li class="alt"><span>  * 静态方法,该方法输入数组并返回数组     </span></li>
<li class=""><span>  *     </span></li>
<li class="alt"><span>  * @param unknown_type $array 输入的数组     </span></li>
<li class=""><span>  * @param unknown_type $in 输入数组的编码     </span></li>
<li class="alt"><span>  * @param unknown_type $out 返回数组的编码     </span></li>
<li class=""><span>  * @return unknown 返回的数组     </span></li>
<li class="alt"><span>  */     </span></li>
<li class=""><span>static public function Conversion($array,$in,$out)      </span></li>
<li class="alt"><span>{      </span></li>
<li class="">
<span>  self::$</span><span class="attribute"><font color="#ff0000">in</font></span><span>=$in;      </span>
</li>
<li class="alt">
<span>  self::$</span><span class="attribute"><font color="#ff0000">out</font></span><span>=$out;      </span>
</li>
<li class=""><span>  return self::arraymyicov($array);      </span></li>
<li class="alt"><span>}      </span></li>
<li class=""><span>/**     </span></li>
<li class="alt"><span>  * 内部方法,循环数组     </span></li>
<li class=""><span>  *     </span></li>
<li class="alt"><span>  * @param unknown_type $array     </span></li>
<li class=""><span>  * @return unknown     </span></li>
<li class="alt"><span>  */     </span></li>
<li class=""><span>static private function arraymyicov($array)      </span></li>
<li class="alt"><span>{      </span></li>
<li class="">
<span>  foreach ($array as $</span><span class="attribute"><font color="#ff0000">key</font></span><span>=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>$value)      </span>
</li>
<li class="alt"><span>  {      </span></li>
<li class="">
<span>   $</span><span class="attribute"><font color="#ff0000">key</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">self</font></span><span>::myiconv($key);      </span>
</li>
<li class="alt"><span>   if (!is_array($value)) {      </span></li>
<li class="">
<span>    $</span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">self</font></span><span>::myiconv($value);      </span>
</li>
<li class="alt"><span>   }else {      </span></li>
<li class="">
<span>    $</span><span class="attribute"><font color="#ff0000">value</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">self</font></span><span>::arraymyicov($value);      </span>
</li>
<li class="alt"><span>   }      </span></li>
<li class=""><span>   $temparray[$key]=$value;      </span></li>
<li class="alt"><span>  }      </span></li>
<li class=""><span>  return $temparray;      </span></li>
<li class="alt"><span>}      </span></li>
<li class=""><span>/**     </span></li>
<li class="alt"><span>  * 替换数组编码     </span></li>
<li class=""><span>  *     </span></li>
<li class="alt"><span>  * @param unknown_type $str     </span></li>
<li class=""><span>  * @return unknown     </span></li>
<li class="alt"><span>  */     </span></li>
<li class=""><span>static private function myiconv($str)      </span></li>
<li class="alt"><span>{      </span></li>
<li class=""><span>  return iconv(self::$in,self::$out,$str);      </span></li>
<li class="alt"><span>}      </span></li>
<li class=""><span>}      </span></li>
<li class="alt">
<span>$</span><span class="attribute"><font color="#ff0000">b</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">array</font></span><span>("测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>array("测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>"测试","测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>"测试","测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>array("测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>"测试")),"fasdf"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>"测试","测试"=</span><span class="tag"><strong><font color="#006699">></font></strong></span><span>"测试 ");      </span>
</li>
<li class="">
<span>$</span><span class="attribute"><font color="#ff0000">a</font></span><span> =</span><span class="attribute-value"><font color="#0000ff">arrayiconv</font></span><span>::Conversion($b,"utf-8","gb2312");      </span>
</li>
<li class="alt"><span>print_r($a);      </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>    </span>
</li>
</ol>

以上代码就是PHP数组转换的具体实现方式,希望对朋友们有所帮助。


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn