note 53507 added to function.array-push
| From: | oneill at c dot dk | Date: | Fri, 03 Jun 2005 20:50:32 +0000 |
| Subject: | note 53507 added to function.array-push | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89883@lists.php.net to get a copy of this message | ||
To insert a value into a non-associative array, I find this simple function does the trick:
function insert_in_array_pos($array, $pos, $value)
{
$result = array_merge(array_slice($array, 0 , $pos), array($value), array_slice($array, $pos));
return $result;
}
Seems an awful lot simpler than the iterative solutions given above...
----
Manual Page -- http://www.php.net/manual/en/function.array-push.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53507
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53507&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53507&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53507&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53507&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53507&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53507&report=yes
Search -- http://master.php.net/manage/user-notes.php