How to convert php array to xml

藏色散人
Release: 2023-03-05 18:10:02
Original
2520 people have browsed it

php array to xml method: first create a PHP sample file; then define an "arrayToXml" method; then use "is_numeric" and other functions to convert array to xml; and finally output the converted xml.

How to convert php array to xml

Recommended: "PHP Video Tutorial"

Code:

/**
 * 数组转xml字符
 * @param  string $xml xml字符串
**/
function arrayToXml($data){
if(!is_array($data) || count($data) <= 0){
return false;
}
$xml = "";
foreach ($data as $key=>$val){
if (is_numeric($val)){
$xml.="<".$key.">".$val."";
}else{
$xml.="<".$key.">";
}
}
$xml.="";
return $xml; 
}
Copy after login

The above is the detailed content of How to convert php array to xml. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!