note 81115 added to ref.array

From: Date: Thu, 14 Feb 2008 18:35:14 +0000
Subject: note 81115 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-136148@lists.php.net to get a copy of this message
This function takes an array, a key and a value. If the key is not an array, it acts just like $array[$key] =& $value; If the key is an array, it recurses in the array, creating nested arrays as necessary. Example: $array = array('A' => array('B' => 'phi')); $key = array('A', 'Z'); $value = 'gamma'; arraySet($array, $key, $value); $array should now be: array('A' => array('B' => 'phi', 'C' => 'gamma')); This is useful for constructing nested arrays from sets of filesystem paths (e.g. 'A/B/C') or structured variable names (e.g. 'A.B.C' or 'A[B][C]') Example: arraySet($array, preg_split('/\//', $path, -1, PREG_SPLIT_NO_EMPTY), $value); function arraySet(array &$array, $key, &$value) { if (is_array($key)) { $keyComponent = array_shift($key); if (empty($key)) { $array[$keyComponent] =& $value; return; } if (!is_array($array[$keyComponent])) { $array[$keyComponent] = array(); } PHP_CodeSniffer_arraySet($array[$keyComponent], $key, $value); return; } $array[$key] =& $value; } ---- Server IP: 216.235.15.211 Probable Submitter: 70.71.27.18 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/81115 Del: integrated -- https://master.php.net/note/delete/81115/integrated Del: useless -- https://master.php.net/note/delete/81115/useless Del: bad code -- https://master.php.net/note/delete/81115/bad+code Del: spam -- https://master.php.net/note/delete/81115/spam Del: non-english -- https://master.php.net/note/delete/81115/non-english Del: in docs -- https://master.php.net/note/delete/81115/in+docs Del: other reasons-- https://master.php.net/note/delete/81115 Reject -- https://master.php.net/note/reject/81115 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136148) next »