{"id":7632,"date":"2022-09-09T17:08:58","date_gmt":"2022-09-09T11:38:58","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/"},"modified":"2022-09-09T17:08:58","modified_gmt":"2022-09-09T11:38:58","slug":"solved-create-an-array-based-on-the-values-in-2-existing-arrays","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/","title":{"rendered":"[Solved] create an array based on the values in 2 existing arrays"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-24386853\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"24386853\" data-parentid=\"24243946\" data-score=\"0\" data-position-on-page=\"3\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<pre><code>&lt;?php\n$rightSide = array(15, 15, 15, 15, 18, 18, 19, 21, 21, 21, 25, 25);\n$leftSide = array(13, 14, 12, 11, 16, 17, 20, 22, 23, 24, 30, 31);\n$rightFlip = array_flip($rightSide);\n\nfor($k=0; $k&lt;count($rightFlip); $k++)\n{\n    $arr25[$k] = $k;\n}\n\n$array25 = array_combine($arr25, $rightFlip);\n\n$k = 0;\nwhile($k&lt;count($array25))\n{\n    if($k==0)\n    {\n        $finArr[0] = $rightSide[0];\n        $repeat_0 = $array25[0] - (-1);\n        echo \"Repeat_0 = \" . $repeat_0. \"&lt;\/br&gt;\";\n        for($i=0; $i&lt;$repeat_0; $i++)\n        {\n            $finArr[$i+1] = $leftSide[$i];\n        }\n    }\n\/*  \n    else if($k==1)\n    {\n        $repeat = $array25[$k] - $array25[$k-1];\n        $repeatPrev = $array25[$k-1] - $repeat[$k-2];\n        $insideUsed = $repeat_0;\n        $finArr[$i+1] = $rightSide[$repeat_0];\n\n        for($j=$i+2; $j&lt;($repeat+$i+2); $j++)\n        {\n\n            $finArr[$j] = $leftSide[$insideUsed];\n            $insideUsed = $insideUsed + 1;\n        }\n    }\n    else if($k==2)\n    {\n        $repeat = $array25[$k] - $array25[$k-1];\n        $repeatPrev = $array25[$k-1] - $array25[$k-2];\n        echo \"Repeat = \" . $repeat. \"&lt;\/br&gt;\";\n        echo \"RepeatPrev = \" . $repeatPrev. \"&lt;\/br&gt;\";\n        $finArr[$j] = $rightSide[$repeat_0 + $repeatPrev];\n        $insideUsed = $repeat_0 + $repeatPrev;\n        for($l=$j+1; $l&lt;($repeat+$j+1); $l++)\n        {\n            $finArr[$l] = $leftSide[$insideUsed];\n            $insideUsed = $insideUsed + 1;\n        }\n    }\n\/*    else if($k==3)\n    {\n        $repeat = $array25[$k] - $array25[$k-1];\n        $repeatPrev = $array25[$k-1] - $array25[$k-2];\n        $repeatPrevPrev = $array25[$k-2] - $array25[$k-3];\n        $finArr[$l] = $rightSide[$repeat_0 + $repeatPrevPrev + $repeatPrev];\n        $insideUsed = $repeat_0 + $repeatPrevPrev + $repeatPrev;\n        for($m=$l+1; $m&lt;($repeat+$l+1); $m++)\n        {\n            $finArr[$m] = $leftSide[$insideUsed];\n            $insideUsed = $insideUsed + 1;\n        }\n    }*\/\n    else \n    {\n        echo \"&lt;\/br&gt; for k = \" . $k . \"&lt;\/br&gt;\";\n        for($n=$k; $n&gt;0; $n--)\n        {\n            $repeat_arr[$n] = $array25[$n] - $array25[$n-1];\n            echo \"Repeat_arr[\". $n . \"] = \". $repeat_arr[$n];\n        }\n\n        $repeat_arr[0] = $array25[0] - (-1);\n        echo \"Repeat_arr 0 = \" . $repeat_arr[0];\n\n        for($I=0; $I&lt;$k; $I++)\n        {\n            $addRepeats[$k] += $repeat_arr[$I];\n        }\n\n        $addRepeats[$k] += $k;\n\n        echo \"addRepeats = \" . $addRepeats[$k];\n\n        for($I=0; $I&lt;$k; $I++)\n        {\n            $added[$k] += $repeat_arr[$I];\n        }\n\n        $finArr[$addRepeats[$k]] = $rightSide[$added[$k]];\n\n        for($I=$addRepeats[$k]+1; $I&lt;($repeat_arr[$k] + $addRepeats[$k] + 1); $I++)\n        {\n            $finArr[$I] = $leftSide[$added[$k]];\n            $added[$k] = $added[$k] + 1;\n        }\n\n    }\n\n    $k++;\n\n}\n\n\n\n\necho \"&lt;table&gt;\";\necho \"&lt;tr&gt;\";\necho \"&lt;th&gt;Array25&lt;\/th&gt;\";\necho \"&lt;th&gt;RightSide&lt;\/th&gt;\";\necho \"&lt;th&gt;LeftSide&lt;\/th&gt;\";\necho \"&lt;th&gt;finArr&lt;\/th&gt;\";\necho \"&lt;\/tr&gt;\";\n\necho \"&lt;tr&gt;\";\necho \"&lt;td&gt;\";\necho \"&lt;pre&gt;\";\nprint_r($array25);\necho \"&lt;\/pre&gt;\";\necho \"&lt;\/td&gt;\";\n\necho \"&lt;td&gt;\";\necho \"&lt;pre&gt;\";\nprint_r($rightSide);\necho \"&lt;\/pre&gt;\";\necho \"&lt;\/td&gt;\";\n\necho \"&lt;td&gt;\";\necho \"&lt;pre&gt;\";\nprint_r($leftSide);\necho \"&lt;\/pre&gt;\";\necho \"&lt;\/td&gt;\";\n\necho \"&lt;td&gt;\";\necho \"&lt;pre&gt;\";\nprint_r($finArr);\necho \"&lt;\/pre&gt;\";\necho \"&lt;\/td&gt;\";\necho \"&lt;\/tr&gt;\";\n\necho \"&lt;\/table&gt;\";\n<\/code><\/pre>\n<p>This answer will be correct no matter how many elements are added or subtracted from rightside array and corresponding elements added \/ subtracted from left side array.. to make changes in array25 array&#8230;&#8230;<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved create an array based on the values in 2 existing arrays <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] &lt;?php $rightSide = array(15, 15, 15, 15, 18, 18, 19, 21, 21, 21, 25, 25); $leftSide = array(13, 14, 12, 11, 16, 17, 20, 22, 23, 24, 30, 31); $rightFlip = array_flip($rightSide); for($k=0; $k&lt;count($rightFlip); $k++) { $arr25[$k] = $k; } $array25 = array_combine($arr25, $rightFlip); $k = 0; while($k&lt;count($array25)) { if($k==0) { $finArr[0] = $rightSide[0]; &#8230; <a title=\"[Solved] create an array based on the values in 2 existing arrays\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\" aria-label=\"More on [Solved] create an array based on the values in 2 existing arrays\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[361,339],"class_list":["post-7632","post","type-post","status-publish","format-standard","hentry","category-solved","tag-arrays","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] create an array based on the values in 2 existing arrays - JassWeb<\/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:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] create an array based on the values in 2 existing arrays - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] &lt;?php $rightSide = array(15, 15, 15, 15, 18, 18, 19, 21, 21, 21, 25, 25); $leftSide = array(13, 14, 12, 11, 16, 17, 20, 22, 23, 24, 30, 31); $rightFlip = array_flip($rightSide); for($k=0; $k&lt;count($rightFlip); $k++) { $arr25[$k] = $k; } $array25 = array_combine($arr25, $rightFlip); $k = 0; while($k&lt;count($array25)) { if($k==0) { $finArr[0] = $rightSide[0]; ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-09T11:38:58+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\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:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] create an array based on the values in 2 existing arrays\",\"datePublished\":\"2022-09-09T11:38:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\"},\"wordCount\":56,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"arrays\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\",\"name\":\"[Solved] create an array based on the values in 2 existing arrays - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-09T11:38:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] create an array based on the values in 2 existing arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] create an array based on the values in 2 existing arrays - JassWeb","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:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] create an array based on the values in 2 existing arrays - JassWeb","og_description":"[ad_1] &lt;?php $rightSide = array(15, 15, 15, 15, 18, 18, 19, 21, 21, 21, 25, 25); $leftSide = array(13, 14, 12, 11, 16, 17, 20, 22, 23, 24, 30, 31); $rightFlip = array_flip($rightSide); for($k=0; $k&lt;count($rightFlip); $k++) { $arr25[$k] = $k; } $array25 = array_combine($arr25, $rightFlip); $k = 0; while($k&lt;count($array25)) { if($k==0) { $finArr[0] = $rightSide[0]; ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/","og_site_name":"JassWeb","article_published_time":"2022-09-09T11:38:58+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] create an array based on the values in 2 existing arrays","datePublished":"2022-09-09T11:38:58+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/"},"wordCount":56,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["arrays","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/","url":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/","name":"[Solved] create an array based on the values in 2 existing arrays - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-09T11:38:58+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-create-an-array-based-on-the-values-in-2-existing-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] create an array based on the values in 2 existing arrays"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/7632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=7632"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/7632\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=7632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=7632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=7632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}