SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using custom keys in arrays

    I am creating an array from a db SELECT, and want the [key] to reflect the id in the table.

    I am getting this error, so I must be doing something wrong.

    Code:
    Parse error: parse error, unexpected T_DOUBLE_ARROW in /file.php on line 18
    My code looks like:

    PHP Code:
    $mmenu=array();
        while(
    $row=mysql_fetch_array($records))
            {
                
    $id $row["id"];
                
    $value $row["menuname"];
                
    array_push($mmenu$id=> $value);
            }
        return 
    $mmenu
    At the moment, I can produce the array, but with its own keys.
    Thanks
    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    instead of
    PHP Code:
    array_push($mmenu$id=> $value); 
    do
    PHP Code:
    $mmenu[$id] = $value
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    instead of
    PHP Code:
    array_push($mmenu$id=> $value); 
    do
    PHP Code:
    $mmenu[$id] = $value

    Thank you sweat, that did it.
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site


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
  •