Convert multidimensional array to XML file in PHP Last Updated : 12 Jul, 2019 Comments Improve Suggest changes Like Article Like Report Given a multi-dimensional array and the task is to convert this array into an XML file. To converting the multi-dimensional array into an xml file, create an XML file and use appendChild() and createElement() function to add array element into XML file. Example: First, create a PHP Multidimensional Array for converting that array into the XML file format. php $array = array ( 'company' => 'Gfg', 'employe' => array ( '0' => array ( 'name' => 'Jatin Das', 'age' => '34' ), '1' => array ( 'name' => 'Mohit Mal', 'age' => '30' ), '2' => array ( 'name' => 'Shubham Jha', 'age' => '24' ), '3' => array ( 'name' => 'Harsha Bhosle', 'age' => '29' ) ) ); Now, you need to create a user-defined function generatXML(). php function generateXML($data) { $title = $data['company']; $rowCount = count($data['employe']); // Create the xml document $xmlDoc = new DOMDocument(); $root = $xmlDoc -> appendChild($xmlDoc -> createElement("geeks")); $root -> appendChild($xmlDoc -> createElement("title", $title)); $root -> appendChild($xmlDoc -> createElement("totalRows", $rowCount)); $tabUsers = $root -> appendChild($xmlDoc -> createElement('rows')); foreach($data['employe'] as $user) { if (!empty($user)) { $tabUser = $tabUsers -> appendChild($xmlDoc -> createElement('employe')); foreach($user as $key => $val) { $tabUser -> appendChild($xmlDoc -> createElement($key, $val)); } } } header("Content-Type: text/plain"); // Make the output $xmlDoc -> formatOutput = true; // Save xml file $file_name = str_replace(' ', '_', $title) . '.xml'; $xmlDoc -> save($file_name); // Return xml file name return $file_name; } Then use generateXML() function and pass array data in it to convert the array to XML in PHP. php generateXML($array); Output: html <geeks> <title>Gfg</title> <totalRows>4</totalRows> <rows> <employe> <name>Jatin Das</name> <age>34</age> </employe> <employe> <name>Mohit Mal</name> <age>30</age> </employe> <employe> <name>Shubham Jha</name> <age>24</age> </employe> <employe> <name>Harsha Bhosle</name> <age>29</age> </employe> </rows> </geeks> Comment More infoAdvertise with us L legendblogsmail Follow Improve Article Tags : TechTips Web Technologies Similar Reads How ToHow to Recover Deleted Photos from WhatsApp [5 Methods]Accidentally deleted an important photo from WhatsApp? Youâre not alone. With billions of messages exchanged daily, itâs common to delete a WhatsApp image by mistake. Fortunately, there are multiple ways to retrieve WhatsApp photos, whether through backups, phone storage, or cloud services.This guid8 min readHow to Delete Discord Servers: Step by Step GuideDiscord is a popular platform that brings people together through voice, video, and text, making it a go-to space for gamers, communities, and friends alike. But as your needs change, you might need to know how to delete a Discord server. Whether you are on Mobile, PC, iPhone, or Android this articl7 min readHow to Fix âThis Copy of Windows is Not Genuineâ Error?The message âThis copy of Windows is not genuineâ can be quite irritating, and it may limit your usage of some features in your machine. This notification message is usually shown when the Windows operating system in question cannot verify its authenticity. This is due to limitations of the Windows6 min readHow to Delete Discord Account: A Complete GuideDiscord is a popular gaming platform that allows users to connect through voice, video, and text. Initially designed for gamers, it has grown into a versatile tool for communities, friends, and teams to chat, collaborate, and share content in real-time. With customizable servers and channels, Discor4 min readFlowchart in Google DocsCreating a flowchart on Google Docs is an efficient way to illustrate processes, organize information, and enhance your documents. If youâre a student, business professional, or project manager, utilizing flowcharts in Google Docs can streamline complex ideas and improve clarity. In this article, we5 min readHow to Password Protect a Google Drive Folder: Comprehensive GuideGoogle Drive is a popular cloud storage service that allows users to store, share, and access their files from anywhere. However, you may want to secure some of your sensitive files by password-protecting them. While Google Drive doesnât offer a built-in password protection feature for folders, ther9 min readHow to Deploy a Replica Set in MongoDB?MongoDB replica sets are crucial for ensuring high availability, fault tolerance, and data redundancy in MongoDB deployments. A replica set is a group of MongoDB instances that maintain the same dataset, offering a reliable solution for production environments.In this article, we will explain the pr5 min readMACHow to Find Your Mac Address?A MAC (Media Access Control) address is a unique identifier assigned to the network interface of a gadget. Whether you're troubleshooting network issues, setting up a secure connection, or filtering devices, knowing how to find your MAC address is essential. This article clarifies how to find your M5 min readMAC Filtering in Computer NetworkThere are two kinds of network Adapters. A wired adapter allows us to set up a connection to a modem or router via Ethernet in a computer whereas a wireless adapter identifies and connects to remote hot spots. Each adapter has a distinct label known as a MAC address which recognizes and authenticate10 min readHow to validate MAC address using Regular ExpressionGiven string str, the task is to check whether the given string is a valid MAC address or not by using Regular Expression. A valid MAC address must satisfy the following conditions: It must contain 12 hexadecimal digits.One way to represent them is to form six pairs of the characters separated with6 min readHow to get the MAC Address â 10 Different Methods â Kali LinuxMAC Address or Media Access Control Address is the unique address that is issued to our system by the network interface controller (NIC) for seamless communication at the DDL (Data Link Layer) of the Network Segment. This MAC address is also used as a network address for different network topologies5 min readExtracting MAC address using PythonMAC address also known as physical address is the unique identifier that is assigned to the NIC (Network Interface Card) of the computer. NIC helps in connection of a computer with other computers in the network. MAC address is unique for all the NIC's. Uses of MAC address : Useful in places where I3 min readAI ToolsAI Tools List: 50+ Top PicksAI tools are software that use artificial intelligence technologies to automate tasks and solve problems. and help to enhance human capabilities. These tools leverage machine learning, natural language processing, and other AI techniques to perform functions.Common Types of AI ToolsChatGPT, Gemini,5 min read10 Best AI Tools to Boost Productivity in 2025In 2025, AI tools are no longer a luxuryâtheyâre a necessity for professionals and businesses aiming to stay ahead in a fast-paced world. The best AI tools have revolutionized productivity across industries by automating mundane tasks, optimizing workflows, and enhancing creativity. From generating14 min readTop 15 AI Testing Tools for Test Automation (2025 Updated)AI for all Types of Software Testing has become an integral part of the software development lifecycle, and with the integration of AI, it has grown into a more efficient and precise process. AI testing tools bring intelligent capabilities like visual recognition, autonomous test creation, and predi14 min readTop 20 Applications of Artificial Intelligence (AI) in 2025Artificial Intelligence is the practice of transforming digital computers into working robots. They are designed in such a way that they can perform any dedicated tasks and also take decisions based on the provided inputs. The reason behind its hype around the world today is its act of working and t13 min readShortcut KeyWindows Keyboard Shortcuts A to Z with PDF (All Windows Versions)Are you searching for the complete A to Z list of Windows hotkeys? Windows keyboard shortcuts are essential for improving productivity, saving time, and performing various tasks more efficiently. Instead of relying solely on a mouse, Windows Keyboard Shortcut Cheat Sheet provides faster ways to navi11 min readMac Keyboard Shortcuts for All Mac Users (2025 Updated)As a Mac user, mastering keyboard shortcuts is an upgrade for improving productivity, navigating macOS effortlessly, and executing tasks quickly. Whether you have newly purchased a Macbook, Shifted from Windows to MacOS, or are an advanced user, knowing the right shortcuts can save you valuable time9 min readTop 20 Excel Shortcuts That You Need To KnowAlthough many of us are already aware of Microsoft Excel, let us still have a basic introduction to it. Microsoft Excel is a very powerful and pretty old application developed by Microsoft in the year 1984, extensively used for spreadsheet processing, business operations, accounting, social media ma6 min readMicrosoft Word Shortcut KeysUsing keyboard shortcuts in Microsoft Word helps you work faster and more easily. Whether you are writing, formatting, or working with tables, these shortcuts let you do tasks quickly without needing the mouse. This guide will show you important shortcuts to help you use Word more efficiently and sa7 min readMicrosoft Office Keyboard ShortcutsMastering MS Office keyboard shortcuts can significantly enhance your productivity and efficiency. Whether you're using Word, Excel, or Outlook, knowing the right shortcuts can save you time and streamline your workflow. In this guide, we'll explore essential Microsoft Office keyboard shortcuts that5 min readGeneral Keyboard Shortcuts For Visual Studio CodeUsing Visual Studio Code keyboard shortcuts can significantly enhance your productivity and efficiency. Whether you're new to the platform or looking to improve your workflow, knowing the most common keyboard shortcuts in Visual Studio Code will help you navigate and edit code faster. This guide cov3 min read Like