note 29518 deleted from function.array-push by philip

From: Date: Fri, 09 Oct 2009 16:40:03 +0000
Subject: note 29518 deleted from function.array-push by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161597@lists.php.net to get a copy of this message
Note Submitter: be at my dot net dot sg ---- Here's a function to add any key variable into array. this function cannot be use if the key and var set are both numbers. <?php function addArray(&$array, $id, $var) { $tempArray = array($var => $id); $array = array_merge ($array, $tempArray); } $myArray= array (); addArray($myArray, 1, 'something'); ?> Displaying: <?php foreach (array_keys($myArray) as $fields) { print $myArray[$fields]; print $fields; } ?> Result: 1 something

« previous php.notes (#161597) next »