Re: PHP Array.Object Names?
Quote:
Originally Posted by
prodigyrick
Hello I'm relatively new to arrays but I have been working with nested arrays this evening.
I have a multi structured object oriented array, or at least thats what I call it. :P
I wish to name the object array and haven't a clue how to do this.
'userInfo' is my Array, and I would like to give it a name. Here is the structure I'm using:
userInfo Object 'var.
www.svn.released.182712.html.usr.class' <--userInfo Array needs a name
[0] String test value
[1] Number 107211
Im guessing I need the userInfo Object Value named. =)
Re: PHP Array.Object Names?
Either use an associative array or an object. It's rather silly to use both.
PHP Code:
$userInfo = array(
'firstname' => 'John',
'lastname' => 'Doe',
'age' => '42'
);
echo $userInfo['firstname'];
Or
PHP Code:
class userInfo {
var $firstname;
var $lastname;
var $age;
function userInfo($firstname, $lastname, $age) {
$this->$firstname = $firstname;
$this->$lastname = $lastname;
$this->$age = $age;
}
}
$user = new $userInfo('John', 'Doe', '42');
echo $user->$firstname;