note 126234 added to function.array-walk

From: Date: Mon, 12 Jul 2021 10:07:28 +0000
Subject: note 126234 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-216597@lists.php.net to get a copy of this message
You can change the key or value with array_walk if you use the temporal returned array in global inside the function. For example: $array = ['a'=>10, 'b'=>20]; $sequence = array (); $newArray = array_values(array_walk($array, 'fn')); function fn(&$val,$key){ global $sequence; $sequence [] = $val; } No need to concern about the place of the internal pointer for the baby array. You have now rewinded, 0 based new array, string key one instead. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 178.239.167.144) ---- Manual Page -- https://php.net/manual/en/function.array-walk.php Edit -- https://main.php.net/note/edit/126234 Del: integrated -- https://main.php.net/note/delete/126234/integrated Del: useless -- https://main.php.net/note/delete/126234/useless Del: bad code -- https://main.php.net/note/delete/126234/bad+code Del: spam -- https://main.php.net/note/delete/126234/spam Del: non-english -- https://main.php.net/note/delete/126234/non-english Del: in docs -- https://main.php.net/note/delete/126234/in+docs Del: other reasons-- https://main.php.net/note/delete/126234 Reject -- https://main.php.net/note/reject/126234 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216597) next »