-
October 31st, 2010, 10:25 PM
#1
PHP Array.Object Names?
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
-
October 31st, 2010, 10:42 PM
#2
Re: PHP Array.Object Names?
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. =)
-
November 1st, 2010, 08:21 AM
#3
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;
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|