note 58705 added to function.array-push

From: Date: Sun, 13 Nov 2005 00:02:06 +0000
Subject: note 58705 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-98496@lists.php.net to get a copy of this message
Further Modification on the array_push_associative function 1. removes seemingly useless array_unshift function that generates php warning 2. adds support for non-array arguments <? // Append associative array elements function array_push_associative(&$arr) { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { foreach ($arg as $key => $value) { $arr[$key] = $value; $ret++; } }else{ $arr[$arg] = ""; } } return $ret; } $items = array("here" => "now"); $moreitems = array("this" => "that"); $theArray = array("where" => "do we go", "here" => "we are today"); echo array_push_associative($theArray, $items, $moreitems, "five") . ' is the size of $theArray.<br />'; echo "<pre>"; print_r($theArray); echo "</pre>"; ?> Yields: 4 is the size of $theArray. Array ( [where] => do we go [here] => now [this] => that [five] => ) ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58705 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58705&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58705&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98496) next »