note 22460 deleted from ref.array by sniper

From: Date: Sat, 18 Oct 2003 18:04:22 +0000
Subject: note 22460 deleted from ref.array by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58844@lists.php.net to get a copy of this message
Note Submitter: webkid%webkid.com ---- A painstakenly written function to add a "value" to a recursive array using a pathlist (also in the format of an array): function recurse($a,$rm,$k,$d){ if (sizeof($rm)==0){$a[$k]=$d; return ($a);} $sh=array_shift($rm); $a[$sh]=recurse ($a[$sh],$rm,$k,$d); return ($a);} Called like this: $ary=recurse($ary, array("level1","level2","level3"),"key",$value); So an array like Array( [0] => a [1] => b [2] => c [d] => Array ( [0] => a [1] => b [c] => Array ( [0] => e [1] => f [2] => g [3] => h [i] => Array ( [0] => n ) ) ) ) Can become Array( [0] => a [1] => b [2] => c [d] => Array ( [0] => a [1] => b [c] => Array ( [0] => e [1] => f [2] => g [3] => h [i] => Array ( [0] => n [key] => data ) ) ) ) With the call $ary=recurse($ary,array("d","c","i"),"key","data");

« previous php.notes (#58844) next »