note 34094 added to ref.array
| From: | simbiosys at rack1 dot php dot net | Date: | Wed, 16 Jul 2003 08:20:21 +0000 |
| Subject: | note 34094 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52170@lists.php.net to get a copy of this message | ||
Here's a function that might be useful for calendaring events. I pulled the rows from MySql and
wanted to add the records to an array.
/*
sample of array: August 20, 2003 has 2 events
$array_events['2003-08-20'][0][0] = "EventA Title"
$array_events['2003-08-20'][0][1] = "EventA Description"
$array_events['2003-08-20'][1][0] = "EventB Title"
$array_events['2003-08-20'][1][1] = "EventB Description"
*/
function addArray(&$array, $key, $val) #$val is an array
{
if (array_key_exists($key, $array)) {
$array[$key] = array_merge ($array[$key], array($val));
}
else
{
# make a temp array who has a key to an array whose first index is the $val array.
$tempArray = array($key => array($val));
$array = array_merge ($array, $tempArray);
}
}
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34094
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34094&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34094&report=yes