note 128186 added to function.array-column

From: Date: Sat, 04 Feb 2023 06:59:36 +0000
Subject: note 128186 added to function.array-column
Groups: php.notes 
Request: Send a blank email to php-notes+get-220142@lists.php.net to get a copy of this message
If you want to rearrage an array with two layers (perhaps from database-requests), then use 'array_walk' instead: <?php $yamlList = [ ['title' => 'hallo ich', 'identifier' => 'ich', 'Klaus'=> 'doof',], ['title' => 'hallo du', 'identifier' => 'du', 'Klaus'=> 'doof',], ['title' => 'hallo er', 'identifier' => 'er', 'Klaus'=> 'doof',], ]; echo ('Input'."\n".print_r($yamlList,true)."\n"); array_walk($yamlList, function (&$value, $key) { $value = [ $value['title'], $value['identifier'], ]; }); echo ("\n".'Output'."\n".print_r($yamlList,true)."\n"); ?> The Result =========== ... Output Array ( [0] => Array ( [0] => hallo ich [1] => ich ) [1] => Array ( [0] => hallo du [1] => du ) [2] => Array ( [0] => hallo er [1] => er ) ) ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.158.213 (proxied: 2003:e4:970f:cce4:5cc8:465e:60e7:607e) ---- Manual Page -- https://php.net/manual/en/function.array-column.php Edit -- https://main.php.net/note/edit/128186 Del: integrated -- https://main.php.net/note/delete/128186/integrated Del: useless -- https://main.php.net/note/delete/128186/useless Del: bad code -- https://main.php.net/note/delete/128186/bad+code Del: spam -- https://main.php.net/note/delete/128186/spam Del: non-english -- https://main.php.net/note/delete/128186/non-english Del: in docs -- https://main.php.net/note/delete/128186/in+docs Del: other reasons-- https://main.php.net/note/delete/128186 Reject -- https://main.php.net/note/reject/128186 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220142) next »