PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
filyr
Forum Newbie
Posts: 5 Joined: Wed Sep 23, 2009 7:04 pm
Post
by filyr » Sun Sep 27, 2009 3:57 am
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!
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Sun Sep 27, 2009 4:58 am
You're not assigning your function's return value to anything.
ell0bo
Forum Commoner
Posts: 79 Joined: Wed Aug 13, 2008 4:15 pm
Post
by ell0bo » Sun Sep 27, 2009 8:18 am
if you wanna use $combined like that, you need to reference it with a global first so PHP knows what scope to look at.
jmaker
Forum Newbie
Posts: 16 Joined: Tue May 21, 2002 11:13 pm
Post
by jmaker » Sun Sep 27, 2009 8:45 am
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);