Click to See Complete Forum and Search --> : PHP Array.Object Names?


prodigyrick
October 31st, 2010, 10:25 PM
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

prodigyrick
October 31st, 2010, 10:42 PM
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. =)

PeejAvery
November 1st, 2010, 08:21 AM
Either use an associative array or an object. It's rather silly to use both.

$userInfo = array(
'firstname' => 'John',
'lastname' => 'Doe',
'age' => '42'
);

echo $userInfo['firstname'];

Or

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;