SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: array syntax

  1. #1
    SitePoint Zealot sifuhall's Avatar
    Join Date
    Jun 2001
    Location
    out of the sidehatch
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array syntax

    What's the syntax to reference an item in an array of hashes (or associative arrays)?

    For example if I have an array called $messagelist that contains several hashes like:
    $message['id']
    $message['senderid']

    etc.

    How would I reference $message['id']?

    ***UPDATE***
    I found the answer and decided to leave this incase anyone else needs the reference.

    This allowed me to view my datastructure very well:
    Code:
    			foreach ($messagelist as $key => $value) {
    				echo "Key: $key; Value: $value<br>\n";
    				foreach ($value as $key => $value) {
    					echo "Key: $key; Value: $value<br>\n";
    				}
    			}
    Last edited by sifuhall; Jul 3, 2001 at 07:51.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, perhaps this will be useful. Two ways to call an associative array through a string :

    $my['foo'] = 'hola';

    print "hello {$my['foo']} howdy";

    print "hello ". $my['foo'] ." howdy";


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •