PHP Array.Object Names?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: PHP Array.Object Names?

  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Arrow 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

  2. #2
    Join Date
    Oct 2010
    Posts
    2

    Re: PHP Array.Object Names?

    Quote Originally Posted by prodigyrick View Post
    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. =)

  3. #3
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,839

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center