Problems with multidimensional arrays and a function
Posted: Wed Dec 08, 2004 3:31 pm
Hi all,
I've been writing a script that puts some posted variables together, then formats them in a certain way and outputs them to the browser.
This is all pretty simple, and I managed to use a multidimensional array to store the first names and last names of the people inputted. However, to save space, I decided to turn this into a function, and then call the function. However, the values don't want to work with the function, and I'm really confused!
First of all, I create the multidimensional array:
Then, I use this function to add new values to the array:
but it doesn't work! When I call the function like this:
The values aren't entered! What am I doing wrong? If I run the contents of the function on their own (as in, not in a function), it works perfectly! How can I get around this?
K
I've been writing a script that puts some posted variables together, then formats them in a certain way and outputs them to the browser.
This is all pretty simple, and I managed to use a multidimensional array to store the first names and last names of the people inputted. However, to save space, I decided to turn this into a function, and then call the function. However, the values don't want to work with the function, and I'm really confused!
First of all, I create the multidimensional array:
Code: Select all
$names = array(array( $first, $last) );Code: Select all
function namearray( $names, $fname, $lname) {
$namesї] = array( $fname, $lname ) ;
}Code: Select all
namearray($names, $first2, $last2);K