{"id":1089,"date":"2025-03-04T03:56:24","date_gmt":"2025-03-04T03:56:24","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1089"},"modified":"2025-03-04T03:56:24","modified_gmt":"2025-03-04T03:56:24","slug":"mwnci-batch-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-batch-function\/","title":{"rendered":"Mwnci batch() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>batch<strong>(<em>array<\/em>,<em>size<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>batch()<\/i> function splits an array into smaller batch (chunk) sizes.<br \/>\nIt is possible that the last chunk is  shorter than its predecessors unless the array\u2019s length is divisible by the desired batch size.  To ensure that all the chunks have an equal length at all times, you can pad the last chunk with default values.<\/p>\n<h2>Example<\/h2>\n<pre>\r\na=1..10\r\nprintln(a)\r\nprintln(batch(a,4))\r\nprintln(batch(a,5))\r\nprintln(batch(a,6))\r\n\r\n\r\n[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\r\n[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]\r\n[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]\r\n[[1, 2, 3, 4, 5, 6], [7, 8, 9, 10]]\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax batch(array,size) Description The batch() function splits an array into smaller batch (chunk) sizes. It is possible that the last chunk is shorter than its predecessors unless the array\u2019s length is divisible by the desired batch size. To ensure that all the chunks have an equal length at all times, you can pad the last &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-batch-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci batch() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1089","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1089"}],"version-history":[{"count":1,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1089\/revisions"}],"predecessor-version":[{"id":1090,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1089\/revisions\/1090"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}