home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomePHP CookbookSearch this book

4.3. Storing Multiple Elements per Key in an Array

4.3.2. Solution

Store the multiple elements in an array:

$fruits = array('red' => array('strawberry','apple'),
                'yellow' => array('banana'));

Or, use an object:

while ($obj = mysql_fetch_object($r)) {
    $fruits[ ] = $obj;
}

4.3.4. See Also

Recipe 4.10 for how to print arrays with commas.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.