{"id":416,"date":"2022-10-27T11:36:10","date_gmt":"2022-10-27T11:36:10","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=416"},"modified":"2022-10-27T11:36:10","modified_gmt":"2022-10-27T11:36:10","slug":"what-is-the-difference-between-array_merge-and-array_combine-2","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/","title":{"rendered":"What is the difference between array_merge and array_combine?"},"content":{"rendered":"\n<p><strong>array_merge() Function<\/strong>: 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 of two or more arrays together into a single array. The merging occurs in such a manner that the values of one array are appended at the end of the previous array. The function takes the list of arrays separated by commas as a parameter that is needed to be merged and returns a new array with merged values of arrays passed in parameter.<\/p>\n\n\n\n<p>Syntax:<\/p>\n\n\n\n<p>array array_merge( $array1, $array2, \u2026., $array n)<br>where, $array1, $array2, . . . are the input arrays that need to be merged.<\/p>\n\n\n\n<p>Example: PHP program to merge two arrays.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Define array1 with keys and values\r\n$array1 = array(\"subject1\" => \"Laravel\",\"subject2\" => \"Jira\");\r\n  \r\n  \r\n\/\/ Define array2 with keys and values\r\n$array2 = array(\"subject3\" => \"Python\",\"subject4\" => \"Bootstrap\");\r\n  \r\n\/\/ Merge both array1 and array2\r\n$final = array_merge($array1, $array2);\r\n  \r\n\/\/ Display merged array\r\nprint_r($final);\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<br>Array<br>(<br>[subject1] => Laravel<br>[subject2] => Jira<br>[subject3] => Python<br>[subject4] => Bootstrap<br>)<\/p>\n\n\n\n<p>Example 2: PHP program to merge multiple arrays.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Define array1 with keys and values\r\n$array1 = array(\"subject1\" => \"Laravel\", \"subject2\" => \"Jira\");\r\n  \r\n  \r\n\/\/ Define array2 with keys and values\r\n$array2 = array(\"subject3\" => \"Python\", \"subject4\" => \"Bootstrap\");\r\n  \r\n\/\/ Define array3 with keys and values\r\n$array3 = array(\"subject5\" => \"Mac\", \"subject6\" => \"Linux\");\r\n  \r\n\/\/ Define array4 with keys and values\r\n$array4 = array(\"subject7\" => \"Data capturing\", \"subject8\" => \"C++\");\r\n  \r\n\/\/ Merge all arrays\r\n$final = array_merge($array1, $array2, $array3, $array4);\r\n  \r\n\/\/ Display merged array\r\nprint_r($final);\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<br>Array<br>(<br>[subject1] => Laravel<br>[subject2] => Jira<br>[subject3] => Python<br>[subject4] => Bootstrap<br>[subject5] => Mac<br>[subject6] => Linux<br>[subject7] => Data capturing<br>[subject8] => C++<br>)<\/p>\n\n\n\n<p><strong>array_combine() Function<\/strong>: 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 i.e. 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<p>Syntax:<\/p>\n\n\n\n<p>array_combine(array1, array2)<br>Where, array1 is the first array with keys and array2 is the second array with the values.<\/p>\n\n\n\n<p>Example: PHP program to combine arrays.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Define array1 with keys \r\n$array1 = array(\"subject1\" ,\"subject2\");\r\n  \r\n\/\/ Define array2 with  values\r\n$array2 = array( \"laravel\", \"jira\");\r\n  \r\n\/\/ Combine two arrays\r\n$final = array_combine($array1, $array2);\r\n  \r\n\/\/ Display merged array\r\nprint_r($final);\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<p>Array<br>(<br>[subject1] => laravel<br>[subject2] => jira<br>)<\/p>\n\n\n\n<p>Example 2: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\r\n  \r\n\/\/ Define array1 with keys \r\n$array1 = array(\"subject1\", \"subject2\", \"subject3\", \"subject4\");\r\n  \r\n\/\/ Define array2 with values\r\n$array2 = array( \"laravel\", \"jira\", \"Python\", \"bootstrap\");\r\n  \r\n\/\/ Combine two arrays\r\n$final = array_combine($array1, $array2);\r\n  \r\n\/\/ Display merged array\r\nprint_r($final);\r\n  \r\n?><\/code><\/pre>\n\n\n\n<p>Output<br>Array<br>(<br>[subject1] => laravel<br>[subject2] => jira<br>[subject3] => Python<br>[subject4] => bootstarp<br>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>array_merge() Function: 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":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,165,113],"tags":[170,171,166,172,169,168,167],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-array","category-function","category-php","tag-array_combine-function","tag-array_merge-function","tag-difference-between-array_merge-and-array_combine","tag-merge-two-or-more-arrays-into-a-single-array","tag-php-program-to-combine-arrays","tag-php-program-to-merge-multiple-arrays","tag-php-program-to-merge-two-arrays"],"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-2\/\" \/>\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: 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-2\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T11:36:10+00:00\" \/>\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=\"2 minutes\" \/>\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-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/\"},\"author\":{\"name\":\"rahulkr kr\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"headline\":\"What is the difference between array_merge and array_combine?\",\"datePublished\":\"2022-10-27T11:36:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/\"},\"wordCount\":266,\"commentCount\":0,\"keywords\":[\"array_combine() Function\",\"array_merge() Function\",\"difference between array_merge and array_combine\",\"merge two or more arrays into a single array.\",\"PHP program to combine arrays.\",\"PHP program to merge multiple arrays.\",\"PHP program to merge two arrays.\"],\"articleSection\":[\"Array\",\"Function\",\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/\",\"url\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/\",\"name\":\"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#website\"},\"datePublished\":\"2022-10-27T11:36:10+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/#\\\/schema\\\/person\\\/e9fd1d88de76754aa189257cd197394d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.devopstrainer.in\\\/blog\\\/what-is-the-difference-between-array_merge-and-array_combine-2\\\/#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\\\/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":"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-2\/","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: 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-2\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T11:36:10+00:00","author":"rahulkr kr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rahulkr kr","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/"},"author":{"name":"rahulkr kr","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"headline":"What is the difference between array_merge and array_combine?","datePublished":"2022-10-27T11:36:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/"},"wordCount":266,"commentCount":0,"keywords":["array_combine() Function","array_merge() Function","difference between array_merge and array_combine","merge two or more arrays into a single array.","PHP program to combine arrays.","PHP program to merge multiple arrays.","PHP program to merge two arrays."],"articleSection":["Array","Function","PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/","url":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/","name":"What is the difference between array_merge and array_combine? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"datePublished":"2022-10-27T11:36:10+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/e9fd1d88de76754aa189257cd197394d"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/what-is-the-difference-between-array_merge-and-array_combine-2\/#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\/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\/416","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=416"}],"version-history":[{"count":4,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":424,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions\/424"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}