note 58321 added to function.array-push

From: Date: Mon, 31 Oct 2005 13:32:43 +0000
Subject: note 58321 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-97880@lists.php.net to get a copy of this message
Previous comment was not fully imitating the array_push behaviour, 1) does not return number of items pushed 2) can only handle one array to push > Revised associative_push function with absolute reference of arg1 array; left unchanged if arg2 > is empty. <?php // Append associative array elements function array_push_associative(&$arr) { $args = func_get_args(); array_unshift($args); // remove &$arr argument foreach ($args as $arg) { if (is_array($arg)) { foreach ($arg as $key => $value) { $arr[$key] = $value; $ret++; } } } return $ret; } $theArray = array(); echo array_push_associative($theArray, $items, $moreitems) . ' items added to $theArray.'; ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58321 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58321&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58321&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97880) next »