亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        PHP實(shí)現(xiàn)數(shù)組array轉(zhuǎn)換成xml的方法

        字號(hào):


            這篇文章主要介紹了PHP實(shí)現(xiàn)數(shù)組array轉(zhuǎn)換成xml的方法,涉及php針對(duì)數(shù)組的遍歷及xml格式文件的構(gòu)造技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
            本文實(shí)例講述了PHP實(shí)現(xiàn)數(shù)組array轉(zhuǎn)換成xml的方法。分享給大家供大家參考,具體如下:
            <?php
            $elementLevel = 0 ;
            function array_Xml($array, $keys = '')
            {
            global $elementLevel;
            if(!is_array($array))
            {
              if($keys == ''){
              return $array;
              }else{
              return "\n<$keys>" . $array . "</$keys>\n";
              }
            }else{
              foreach ($array as $key => $value)
              {
              $haveTag = true;
              if (is_numeric($key))
              {
               $key = $keys;
               $haveTag = false;
              }
              if($elementLevel == 0 )
              {
               $startElement = "<$key>";
               $endElement = "</$key>";
              }
              $text .= $startElement;
              if(!$haveTag)
              {
               $elementLevel++;
               $text .= "<$key>" . array_Xml($value, $key). "</$key>\n";
              }else{
               $elementLevel++;
               $text .= array_Xml($value, $key);
              }
              $text .= $endElement;
              }
            }
            return $text;
            }
            $array = array(
            "employees" => array(
            "employee" => array(
            array(
            "name" => "name one",
            "position" => "position one"
            ),
            array(
            "name" => "name two",
            "position" => "position two"
            ),
            array(
            "name" => "name three",
            "position" => "position three"
            )
            )
            )
            );
            echo array_Xml($array);
            ?>
            希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。