{"id":3281,"date":"2022-09-23T09:00:19","date_gmt":"2022-09-23T09:00:19","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3281"},"modified":"2023-03-27T12:44:53","modified_gmt":"2023-03-27T12:44:53","slug":"append","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3281","title":{"rendered":"Append"},"content":{"rendered":"\n<p>Append can be used to add items to the end of an array. This can be useful for merging static and dynamic data.<\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">array append(array $input, any $items)<\/code><\/pre>\n\n\n\n<p>Appends $items to the end of the $input array.<\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$input:<\/strong> The array to append items to.<br><strong>$items: <\/strong>The items to append to the input array.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"Array\": [\"a\", \"b\", \"c\"]\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    NewArray: append(Array, 'd', 'e')\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"NewArray\": [\n        \"a\",\n        \"b\",\n        \"c\",\n        \"d\",\n        \"e\"\n    ]\n}<\/code><\/pre>\n\n\n\n<p>In this example, the separate string values of &#8220;d&#8221; and &#8220;e&#8221; are added to the &#8220;Array&#8221; of strings.<\/p>\n\n\n\n<p>Any value (string, object, array, integer, etc.) can be appended. <\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Manual append\/prepend<\/strong><\/p>\n\n\n\n<p>In the above example, the result could have been achieved without using the Append() function, by simply creating an additional array and flattening it afterward. Like this:<\/p>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    NewArray: [Arr, 'd', 'e'][]\n}<\/code><\/pre>\n\n\n\n<p>The same trick can be used to prepend items in an array. This is useful since there is no built-in function to prepend like there is for appending.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Append can be used to add items to the end of an array. This can be useful for merging static and dynamic data. Syntax Appends $items to the end of the $input array. Parameters $input: The array to append items to.$items: The items to append to the input array. Example In this example, the separate [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":271,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3281"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3281"}],"version-history":[{"count":4,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3281\/revisions"}],"predecessor-version":[{"id":3798,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3281\/revisions\/3798"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}