{"id":380,"date":"2022-10-27T07:11:50","date_gmt":"2022-10-27T07:11:50","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=380"},"modified":"2022-10-28T07:23:48","modified_gmt":"2022-10-28T07:23:48","slug":"what-is-the-difference-between-array_merge-and-array_combine","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/","title":{"rendered":"What is the difference between array_merge and array_combine?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">array_merge() Function<\/h2>\n\n\n\n<p><strong>&nbsp;<\/strong>The <strong>array_merge()<\/strong> function is used to merge two or more arrays into a single array. This function is used to merge the elements or values of two or more arrays together into a single array. it always work with index array and associative array<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">syntax<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array array_merge( $array1, $array2, ...., $array n)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg\" alt=\"\" class=\"wp-image-469\" width=\"389\" height=\"395\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg 331w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111-296x300.jpg 296w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  \n\n$team1 = array(\"shivam\",\"dharmu sir\",\"raj sir\");\n  \n \n$team2 = array(\"rahul\",\"roshan\",\"avinash\");\n  \n\n$team3 = array_merge($team1, $team2);\n  \necho \"&lt;pre&gt;\";\nprint_r($team3);\necho \"&lt;\/pre&gt;\";\n  \n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">output<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Array\n(\n    &#91;0] =&gt; shivam\n    &#91;1] =&gt; dharmu sir\n    &#91;2] =&gt; raj sir\n    &#91;3] =&gt; rahul\n    &#91;4] =&gt; roshan\n    &#91;5] =&gt; avinash\n)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">array_combine() Function<\/h2>\n\n\n\n<p>The array_combine() function is used to combine two arrays and create a new array by using one array for keys and another array for values, all elements of one array will be the keys of new array and all elements of the second array will be the values of this new array.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">syntax<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>array_combine(array1, array2)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"432\" src=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/222.png\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/222.png 882w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/222-300x147.png 300w, https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/222-768x376.png 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  \n\n$team1 = array(\"shivam\",\"dharmu sir\",\"raj sir\");\n  \n \n$age = array(\"20\",\"22\",\"24\");\n  \n\n$team3 = array_combine($team1, $age);\n  \necho \"&lt;pre&gt;\";\nprint_r($team3);\necho \"&lt;\/pre&gt;\";\n  \n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">output<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>Array\n(\n    &#91;shivam] =&gt; 20\n    &#91;dharmu sir] =&gt; 22\n    &#91;raj sir] =&gt; 24\n)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Difference b\/w array_merge() and array_conbine()-<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>S.N<\/td><td><strong>array_merge()<\/strong><\/td><td><strong>array_combine()<\/strong><\/td><\/tr><tr><td>1<\/td><td>This function merges the two or more arrays.<\/td><td>This array combine only two arrays.<\/td><\/tr><tr><td>2<\/td><td>This function merges &nbsp;the arrays such that all the arrays have keys and values.<\/td><td>containing keys and another array containing values.<\/td><\/tr><tr><td>3<\/td><td>The arrays are appended at the end of the first array.<\/td><td>The arrays are combined.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>array_merge() Function &nbsp;The array_merge() function is used to merge two or more arrays into a single array. This function is used to merge the elements or values&#8230; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-380","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is the difference between array_merge and array_combine? - 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\/what-is-the-difference-between-array_merge-and-array_combine\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"array_merge() Function &nbsp;The array_merge() function is used to merge two or more arrays into a single array. This function is used to merge the elements or values...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T07:11:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-28T07:23:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg\" \/>\n<meta name=\"author\" content=\"shivam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shivam\" \/>\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\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/\"},\"author\":{\"name\":\"shivam\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"headline\":\"What is the difference between array_merge and array_combine?\",\"datePublished\":\"2022-10-27T07:11:50+00:00\",\"dateModified\":\"2022-10-28T07:23:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/\"},\"wordCount\":187,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/111.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/\",\"name\":\"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/111.jpg\",\"datePublished\":\"2022-10-27T07:11:50+00:00\",\"dateModified\":\"2022-10-28T07:23:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/0c8259479972d3d18994f88df3dc8d53\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/111.jpg\",\"contentUrl\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/111.jpg\",\"width\":331,\"height\":336},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is the difference between array_merge and array_combine?\"}]},{\"@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\\\/0c8259479972d3d18994f88df3dc8d53\",\"name\":\"shivam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"caption\":\"shivam\"},\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/author\\\/shivam\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is the difference between array_merge and array_combine? - 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\/what-is-the-difference-between-array_merge-and-array_combine\/","og_locale":"en_US","og_type":"article","og_title":"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps","og_description":"array_merge() Function &nbsp;The array_merge() function is used to merge two or more arrays into a single array. This function is used to merge the elements or values...","og_url":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T07:11:50+00:00","article_modified_time":"2022-10-28T07:23:48+00:00","og_image":[{"url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg","type":"","width":"","height":""}],"author":"shivam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shivam","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/"},"author":{"name":"shivam","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"headline":"What is the difference between array_merge and array_combine?","datePublished":"2022-10-27T07:11:50+00:00","dateModified":"2022-10-28T07:23:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/"},"wordCount":187,"commentCount":0,"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/","url":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/","name":"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#primaryimage"},"image":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#primaryimage"},"thumbnailUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg","datePublished":"2022-10-27T07:11:50+00:00","dateModified":"2022-10-28T07:23:48+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#primaryimage","url":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg","contentUrl":"https:\/\/www.devopstrainer.in\/blog\/wp-content\/uploads\/2022\/10\/111.jpg","width":331,"height":336},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"What is the difference between array_merge and array_combine?"}]},{"@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\/0c8259479972d3d18994f88df3dc8d53","name":"shivam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","caption":"shivam"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/shivam\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/380","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=380"}],"version-history":[{"count":3,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions\/471"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}