note 126953 added to function.array-column

From: Date: Wed, 23 Mar 2022 18:01:57 +0000
Subject: note 126953 added to function.array-column
Groups: php.notes 
Request: Send a blank email to php-notes+get-217763@lists.php.net to get a copy of this message
The following function may be useful to create columns from all values of indexed arrays: function array_column_all(array $arrays): array { $output = []; $columnCount = count($arrays[0]); for ($i = 0; $i < $columnCount; $i++) { $output [] = array_column($arrays, $i); } return $output; } Use: ----- array_column_all( [ ['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3'], ] ); This will output: ------------------- Array ( [0] => Array ( [0] => A1 [1] => B1 [2] => C1 ) [1] => Array ( [0] => A2 [1] => B2 [2] => C2 ) [2] => Array ( [0] => A3 [1] => B3 [2] => C3 ) ) ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 103.51.56.198) ---- Manual Page -- https://php.net/manual/en/function.array-column.php Edit -- https://main.php.net/note/edit/126953 Del: integrated -- https://main.php.net/note/delete/126953/integrated Del: useless -- https://main.php.net/note/delete/126953/useless Del: bad code -- https://main.php.net/note/delete/126953/bad+code Del: spam -- https://main.php.net/note/delete/126953/spam Del: non-english -- https://main.php.net/note/delete/126953/non-english Del: in docs -- https://main.php.net/note/delete/126953/in+docs Del: other reasons-- https://main.php.net/note/delete/126953 Reject -- https://main.php.net/note/reject/126953 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217763) next »