cwncool Posted April 30, 2007 Share Posted April 30, 2007 I've always used mysql_fetch_array to get arrays for data, but I'm wondering what the difference between mysql_fetch_array and mysql_fetch_assoc is... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/ Share on other sites More sharing options...
john010117 Posted April 30, 2007 Share Posted April 30, 2007 Looking it up helps. mysql_fetch_array mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/#findComment-241358 Share on other sites More sharing options...
cwncool Posted April 30, 2007 Author Share Posted April 30, 2007 I did look both of them up in the php manual before posting here. The only thing I noticed different, was fetch_array, can fetch any type of array, while fetch_assoc only fetches associative arrays. I don't know what the different type of arrays mean though. I guess a better question to ask would have been: What's the difference between a MYSQL_ASSOC and a MYSQL_NUM array? Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/#findComment-241360 Share on other sites More sharing options...
trq Posted April 30, 2007 Share Posted April 30, 2007 mysql_fetch_array fetches both an associative and a numeric array unless you specify otherwise, thus making it a little less efficient then mysql_fetch_assoc if you want to use associative arrays. Associative array allow you to index by name, not number. It makes you code allot more readable. Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/#findComment-241361 Share on other sites More sharing options...
cwncool Posted April 30, 2007 Author Share Posted April 30, 2007 Okay. Thanks. I sort of thought that, but I wasn't sure. I guess I've been using associative arrays all along anyway. lol. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/#findComment-241363 Share on other sites More sharing options...
trq Posted April 30, 2007 Share Posted April 30, 2007 I guess I've been using associative arrays all along anyway. Well, if your after associative arrays then mysql_fetch_assoc is slightly more efficient then mysql_fetch_array because that is all it returns. Quote Link to comment https://forums.phpfreaks.com/topic/49261-mysql_fetch_array-vs-mysql_fetch_assoc/#findComment-241366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.