note 29518 modified in function.array-push by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:48:22 +0000 |
| Subject: | note 29518 modified in function.array-push by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79859@lists.php.net to get a copy of this message | ||
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
--was--
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.
function addArray(&$array, $id, $var)
{
$tempArray = array($var => $id);
$array = array_merge ($array, $tempArray);
}
$myArray= array ();
addArray($myArray, 1, 'something');
Displaying:
foreach (array_keys($myArray) as $fields)
{
print $myArray[$fields];
print $fields;
}
Result:
1
something
http://php.net/manual/en/function.array-push.php