Which is a better/faster way to index sql arrays. $variable['field'] or $variable[0]

Discussion in 'PHP' started by x0x, Jul 12, 2009.

  1. #1
    I think using the field name is more professional and better but I'm not sure.
     
    x0x, Jul 12, 2009 IP
  2. Beginn3R

    Beginn3R Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $variable['field'] is better, then sometimes you dont need to write all values, it gets them all in once.
    or else with $variable[0] you need to do like:
    $variable[0];
    $variable[1];
    $variable[2];
    $variable[3];
    $variable[4];
    and more :p
     
    Beginn3R, Jul 12, 2009 IP
  3. co.ador

    co.ador Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have heard that index is faster

    mysql_fetch_assoc() is faster than mysql_fetch_row that what i heard. I have used both indeed mysql_fetch_array seem faster. There is one function call mysql_fetch_array which addresses both by index and by field.

    mysql_fetch_assoc addresses by index and mysql_fetch_row by field.

    take a look at this thread in siteforum.com

    http://www.sitepoint.com/forums/showthread.php?t=624231
     
    co.ador, Jul 12, 2009 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.
     
    ThePHPMaster, Jul 12, 2009 IP
  5. Jontish

    Jontish Well-Known Member

    Messages:
    1,565
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    #5
    $variable['field'] for sure, IMO
     
    Jontish, Jul 12, 2009 IP