{"id":428,"date":"2022-10-27T12:42:51","date_gmt":"2022-10-27T12:42:51","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=428"},"modified":"2022-10-28T09:54:08","modified_gmt":"2022-10-28T09:54:08","slug":"how-to-create-an-array-from-a-php-string-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/","title":{"rendered":"How to create an array from a PHP string? explain with example"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg\" alt=\"\" class=\"wp-image-499\" width=\"760\" height=\"324\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg 680w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string-300x128.jpg 300w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string-678x290.jpg 678w\" sizes=\"auto, (max-width: 760px) 100vw, 760px\" \/><figcaption><strong><em>Create an array from a PHP string<\/em><\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<p>We have given an array and the task is to convert the array elements into a string. In this query, we are using two methods to convert an array to a string.<\/p>\n\n\n\n<p>Method 1: <strong>Using implode() function:<\/strong> The implode() method is an inbuilt function in PHP and is used to join the elements of an array. The implode() method is an alias for PHP | join() function and works exactly same as that of join() function.<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<p>string implode($separator, $array)<br>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php  \n  \n\/\/ Declare an array \n$arr = array(\"Welcome\",\"to\", \"DevopforDevops\", \n    \"A\", \"Computer\",\"Language\",\"program\");  \n    \n\/\/ Converting array elements into\n\/\/ strings using implode function\necho implode(\" \",$arr);\n   \n?&gt;<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<p>Welcome to DevopsforDevops A Computer Language Program<br>Method 2: <strong>Using json_encode() Function<\/strong>: The json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation.<br>Syntax:<\/p>\n\n\n\n<p>string json_encode( $value, $option, $depth )<br>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php \n  \n\/\/ Declare multi-dimensional array \n$value = array( \n    \"name\"=&gt;\"DFD\", \n    array( \n        \"email\"=&gt;\"dce@dfd.com\", \n        \"mobile\"=&gt;\"XXXXXXXXXX\"\n    ) \n); \n  \n\/\/ Use json_encode() function \n$json = json_encode($value); \n  \n\/\/ Display the output \necho($json); \n  \n?&gt; \nOutput:\n\n{\"name\":\"DFD\",\"0\":{\"email\":\"dce@dfd.com\",\"mobile\":\"XXXXXXXXXX\"}}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We have given an array and the task is to convert the array elements into a string. In this query, we are using two methods to convert&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,178,165,113,177],"tags":[179,184,182,183,185,181],"class_list":["post-428","post","type-post","status-publish","format-standard","hentry","category-array","category-array-elements","category-function","category-php","category-php-string","tag-create-an-array-from-a-php","tag-inbuilt-function-in-php","tag-json_encode-function","tag-multi-dimensional-array","tag-php-string","tag-using-implode-function"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"We have given an array and the task is to convert the array elements into a string. In this query, we are using two methods to convert...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T12:42:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-28T09:54:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg\" \/>\n<meta name=\"author\" content=\"rahulkr kr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rahulkr kr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/\"},\"author\":{\"name\":\"rahulkr kr\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"headline\":\"How to create an array from a PHP string? explain with example\",\"datePublished\":\"2022-10-27T12:42:51+00:00\",\"dateModified\":\"2022-10-28T09:54:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/\"},\"wordCount\":141,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/array-from-php-string.jpg\",\"keywords\":[\"create an array from a PHP\",\"inbuilt function in PHP\",\"json_encode() Function\",\"multi-dimensional array\",\"PHP string\",\"Using implode() function\"],\"articleSection\":[\"Array\",\"Array Elements\",\"Function\",\"PHP\",\"PHP String\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/\",\"name\":\"How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/array-from-php-string.jpg\",\"datePublished\":\"2022-10-27T12:42:51+00:00\",\"dateModified\":\"2022-10-28T09:54:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/array-from-php-string.jpg\",\"contentUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/array-from-php-string.jpg\",\"width\":680,\"height\":290},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/how-to-create-an-array-from-a-php-string-explain-with-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create an array from a PHP string? explain with example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\",\"name\":\"DevOps | SRE | DevSecOps\",\"description\":\"Automation means Cost, Quality, Time\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\",\"name\":\"rahulkr kr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g\",\"caption\":\"rahulkr kr\"},\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/author\\\/rahulkr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/","og_locale":"en_US","og_type":"article","og_title":"How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps","og_description":"We have given an array and the task is to convert the array elements into a string. In this query, we are using two methods to convert...","og_url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T12:42:51+00:00","article_modified_time":"2022-10-28T09:54:08+00:00","og_image":[{"url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg","type":"","width":"","height":""}],"author":"rahulkr kr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rahulkr kr","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/"},"author":{"name":"rahulkr kr","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"headline":"How to create an array from a PHP string? explain with example","datePublished":"2022-10-27T12:42:51+00:00","dateModified":"2022-10-28T09:54:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/"},"wordCount":141,"commentCount":0,"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg","keywords":["create an array from a PHP","inbuilt function in PHP","json_encode() Function","multi-dimensional array","PHP string","Using implode() function"],"articleSection":["Array","Array Elements","Function","PHP","PHP String"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/","url":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/","name":"How to create an array from a PHP string? explain with example - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#primaryimage"},"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg","datePublished":"2022-10-27T12:42:51+00:00","dateModified":"2022-10-28T09:54:08+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#primaryimage","url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg","contentUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/array-from-php-string.jpg","width":680,"height":290},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/how-to-create-an-array-from-a-php-string-explain-with-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to create an array from a PHP string? explain with example"}]},{"@type":"WebSite","@id":"https:\/\/www.devopstrainer.in\/blog\/#website","url":"https:\/\/www.devopstrainer.in\/blog\/","name":"DevOps | SRE | DevSecOps","description":"Automation means Cost, Quality, Time","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopstrainer.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d","name":"rahulkr kr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/79531cbaf0b831cebc9631f6ac28f21fb3fb0dc2615eeecdeeec43038b513473?s=96&d=mm&r=g","caption":"rahulkr kr"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/rahulkr\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=428"}],"version-history":[{"count":3,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/428\/revisions"}],"predecessor-version":[{"id":501,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/428\/revisions\/501"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}