Arrays are not automatically passed by reference in PHP (unlike C, for instance). As with other variables, however, you can write your functions to accept arrays as pass-by-reference arguments. Of course, this applies only to PHP 4.
Code:
Create an array of user information with defaults, then fill it with information. */
$user_info = array('lastname' => '',
'initial' => '',
'firstname' => '',
'homedir' => '');
$user_info['lastname'] = 'User';
$user_info['initial'] = 'L.';
$user_info['firstname'] = 'Joe';
$user_info['homedir'] = '/home/joeluser';
/* Filling an indexed array with the letters of the English alphabet. */
$arr = array();
for ($i = 97; $i < 123; $i++) {
$arr[] = chr($i);
}
print_r($arr);
/* Do the same thing, but make an array containing two arrays, one of uppercase
* letters and one of lowercase. */
$arr = array();
for ($i = 97; $i < 123; $i++) {
$arr['lowercase'][] = chr($i);
$arr['uppercase'][] = chr($i - 32);
}
print_r($arr);
Bookmarks