note 27191 deleted from ref.array by sniper

From: Date: Sat, 18 Oct 2003 18:03:33 +0000
Subject: note 27191 deleted from ref.array by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58837@lists.php.net to get a copy of this message
Note Submitter: atnak@chejz.com ---- Here's a function that will set an arbitary array field to an arbitary value: function array_field_to_value(&$array, $field, $value) { if ( is_array($field) ) { $head = array_shift($field); if ( count($field) == 0 ) { $array[$head] = $value; } else { array_field_to_value($array[$head], $field, $value); } } else { $array[$field] = $value; } } I find this useful for doing things like this: $post_arg = "1,10,pizza,orange,cat"; $post_val = "something"; $myarray = array(); array_field_to_value($myarray, explode(',', $post_arg), $post_val); Which gets the same results as doing: $myarray = array(); $myarray['1']['10']['pizza']['orange']['cat'] = "something";

« previous php.notes (#58837) next »