note 127715 added to function.array-change-key-case

From: Date: Wed, 12 Oct 2022 04:15:03 +0000
Subject: note 127715 added to function.array-change-key-case
Groups: php.notes 
Request: Send a blank email to php-notes+get-219666@lists.php.net to get a copy of this message
Array of partitions with always the same number of sub-array indexes. <?php function partitionFixedSubArray($array, $length, $empty_space) { $result = []; if ( sizeof($array) ) { $result = array_chunk($array, $length); $last_array_count = sizeof(end($result)); if ($last_array_count < $length) { for ($i = $last_array_count; $i < $length; $i++) { array_push($result[key($result)], $empty_space); } } } return $result; } $employees = [ "Paidi", "Paijo", "Darno", "Kusnan", "Mukidi", "Sarno", "Nurdin", "Parmen", "Sukinah", "Sartini", "Sukijan", "Yono", "Supoyo" ]; echo "<pre>"; print_r(partitionFixedSubArray($employees, 5, "empty space")); echo "</pre>"; ?> Output: Array ( [0] => Array ( [0] => Paidi [1] => Paijo [2] => Darno [3] => Kusnan [4] => Mukidi ) [1] => Array ( [0] => Sarno [1] => Nurdin [2] => Parmen [3] => Sukinah [4] => Sartini ) [2] => Array ( [0] => Sukijan [1] => Yono [2] => Supoyo [3] => empty space [4] => empty space ) ) ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.161 (proxied: 139.255.135.141) ---- Manual Page -- https://php.net/manual/en/function.array-change-key-case.php Edit -- https://main.php.net/note/edit/127715 Del: integrated -- https://main.php.net/note/delete/127715/integrated Del: useless -- https://main.php.net/note/delete/127715/useless Del: bad code -- https://main.php.net/note/delete/127715/bad+code Del: spam -- https://main.php.net/note/delete/127715/spam Del: non-english -- https://main.php.net/note/delete/127715/non-english Del: in docs -- https://main.php.net/note/delete/127715/in+docs Del: other reasons-- https://main.php.net/note/delete/127715 Reject -- https://main.php.net/note/reject/127715 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219666) next »