Page 1 of 1

2 easy questions

Posted: Sun Sep 27, 2009 3:57 am
by filyr
1. Why doesnt this show me my arrays combined?

Code: Select all

function nameage($name, $age){
 
$combined = array_combine($name, $age);
return $combined;
 
}
 
$name = array("Floyd","Morrison","Leonard");
$age = array(27,24,42);
 
nameage($name, $age);
 
print_r($combined);

2. Im making a guestbook wich is writing and getting data from a text file. But i want the newest post on top instead of filling it on downwards. Any idea how to solve this? Thanks a lot!

Re: 2 easy questions

Posted: Sun Sep 27, 2009 4:58 am
by jackpf
You're not assigning your function's return value to anything.

Re: 2 easy questions

Posted: Sun Sep 27, 2009 8:18 am
by ell0bo
if you wanna use $combined like that, you need to reference it with a global first so PHP knows what scope to look at.

Re: 2 easy questions

Posted: Sun Sep 27, 2009 8:45 am
by jmaker
jackpf wrote:You're not assigning your function's return value to anything.

Code: Select all

 
function nameage($name, $age){
    $combined = array_combine($name, $age);
    return $combined; 
}
 
$name = array("Floyd","Morrison","Leonard");
$age = array(27,24,42);
 
$combined = nameage($name, $age);
 
print_r($combined);