Gary Mailer wrote:
Hmm not quite what i wanted.
I want to have an array that contains the section name and the id of the section (in a function). Then i can use that 2 dimensional array in other functions
The problem is that i can return either the name or the id from the function but not both?
Anyone got ideas?
Well, that's not what you asked for 🙂
You wanted to know how to access the key and value items, not create a new array by keys.
Anyway...
So I don't have to repeat myself use what I gave you in the prior example because you need that. What MySQL returns is not an array, it's a resource that is called a result set, but an array an a resource are two different things. So we first must parse out all the rows from the resource into an array.
So now that we got that covered and we have a hash table for parsing...
<?
for ($i=0;$i<count(array_keys($myArray));$i++) {
$sectionArray[$myArray[$i]['section']] = $myArray[$i]['id'];
}
}
/ Your array should look like
[section]=>id /
// now put it to the GLOBAL scope..
$GLOBALS['sectionArray'] = $sectionArray;
// now create your function...
function myFuncName($vals) {
//in here you can call your array as follows...
print_r($GLOBALS['sectionArray']);
}
// and run it.
myFuncName('');
?>
And that should do it.