note 124524 added to function.array-column

From: Date: Thu, 19 Dec 2019 18:06:11 +0000
Subject: note 124524 added to function.array-column
Groups: php.notes 
Request: Send a blank email to php-notes+get-213557@lists.php.net to get a copy of this message
For those who may need to return more than one column: function array_columns($input, $columns=array(), $index_key=null) { $result = array(); $idx_list = array(); if (is_scalar($index_key) && !empty($index_key)) { $idx_list = array_column($input, $index_key); } else { $idx_list = array_fill(0, count($input)); } foreach ($columns as $key) { if (is_scalar($key) && !empty($key)) { reset($idx_list); foreach (array_column($input, $key) as $value) { $idx = current($idx_list); if (!isset($result[$idx])) { $result[$idx] = array(); } $result[$idx][$key] = $value; next($idx_list); } } } return $result; } ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 50.73.73.161) ---- Manual Page -- http://php.net/manual/en/function.array-column.php Edit -- https://master.php.net/note/edit/124524 Del: integrated -- https://master.php.net/note/delete/124524/integrated Del: useless -- https://master.php.net/note/delete/124524/useless Del: bad code -- https://master.php.net/note/delete/124524/bad+code Del: spam -- https://master.php.net/note/delete/124524/spam Del: non-english -- https://master.php.net/note/delete/124524/non-english Del: in docs -- https://master.php.net/note/delete/124524/in+docs Del: other reasons-- https://master.php.net/note/delete/124524 Reject -- https://master.php.net/note/reject/124524 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213557) next »