Problem returning array
Posted: Sat Sep 30, 2006 3:47 pm
I have an array declared like this:
Then I use three separate functions to get the 3 keys
I call these from another file as:
Now, these should be returning arrays, thus $sec1, $sec2 and $sec3 will hold arrays. The problem is that it's not doing what it should...
but if I do this:
And this assigns arrays to the $sec# variables.
Why doesn't it work if I return an array from functions, but it works if I access the $sections array directly?
Code: Select all
$sections = array('Section 1' => array('something', 'something'), 'Section 2' => array('something', 'something'), 'Section 3' => array('something', 'something'));Code: Select all
function getSection1() {
return $sections['Section 1'];
}
function getSection2() {
return $sections['Section 2'];
}
function getSection3() {
return $sections['Section 3'];
}Code: Select all
$sec1 = getSection1();
$sec2 = getSection2();
$sec3 = getSection3();but if I do this:
Code: Select all
$sec1 = $sections['Section 1'];
$sec2 = $sections['Section 2'];
$sec3 = $sections['Section 3'];Why doesn't it work if I return an array from functions, but it works if I access the $sections array directly?