hvle Posted July 6, 2006 Share Posted July 6, 2006 hi guys,I have 2 ways of storing record in an array, and I wanna know which one is better (efficiency).method 1:$book[] = array('name' => 'name1', 'email' => 'email1');$book[] = array('name' => 'name2', 'email' => 'email2');$book[] = array('name' => 'name3', 'email' => 'email3');method 2:$book['name'] = array('name1', 'name2', 'name3');$book['email'] = array('email1', 'email2', 'email3');thank you very much for any suggestion Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/ Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 personally, i'd go for method 1. Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53916 Share on other sites More sharing options...
effigy Posted July 6, 2006 Share Posted July 6, 2006 I prefer a hash (associative array). I'm not sure if there are any efficiency differences; if there are, it would depend on how many records you are storing and what you are doing with them. Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53918 Share on other sites More sharing options...
Buyocat Posted July 6, 2006 Share Posted July 6, 2006 I'd go one step further, if you can, and make it:[code]books = array(book1 => array(name => Catch22, email =>someemail)...))[/code] Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53947 Share on other sites More sharing options...
hvle Posted July 6, 2006 Author Share Posted July 6, 2006 method 1 may seem very easy to manipulate, but I got a lot of trouble w/ sorting, and finding out duplication.A hash method, can you explain what it is?The # of records are reasonably small considering # of addresses in your address book, so the number is around 5 to 200. I need to do some database operation like sorting, filtering duplication, insertion. These operations done inside script, so no database involved.thanks Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53951 Share on other sites More sharing options...
hvle Posted July 6, 2006 Author Share Posted July 6, 2006 [quote author=Buyocat link=topic=99667.msg392609#msg392609 date=1152201958]I'd go one step further, if you can, and make it:[code]array(book => array(book1 => array(name => Catch22, email =>someemail)...)))[/code][/quote]can you point out the advantage with this way cuz I can not see it. Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53954 Share on other sites More sharing options...
Buyocat Posted July 6, 2006 Share Posted July 6, 2006 There are all sorts of functions of sorting/sifting through arrays. I'll let you choose which ones suit your needs...http://us3.php.net/array Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53955 Share on other sites More sharing options...
effigy Posted July 6, 2006 Share Posted July 6, 2006 [url=http://www.samspublishing.com/articles/article.asp?p=31840&seqNum=6&rl=1]Sorting Multidimensional Arrays[/url] Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53963 Share on other sites More sharing options...
hvle Posted July 6, 2006 Author Share Posted July 6, 2006 that's a good link http://us3.php.net/arrayThank you very much.array_multisort, it doesn't explain much in the manual. Link to comment https://forums.phpfreaks.com/topic/13854-array-problem/#findComment-53973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.