2 easy questions

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

Post Reply
filyr
Forum Newbie
Posts: 5
Joined: Wed Sep 23, 2009 7:04 pm

2 easy questions

Post 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!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: 2 easy questions

Post by jackpf »

You're not assigning your function's return value to anything.
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: 2 easy questions

Post 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.
jmaker
Forum Newbie
Posts: 16
Joined: Tue May 21, 2002 11:13 pm

Re: 2 easy questions

Post 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);
 
Post Reply