Re: Re: Extracting multi dimensional array value

From: Date: Sun, 03 May 2015 21:03:10 +0000
Subject: Re: Re: Extracting multi dimensional array value
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-324858@lists.php.net to get a copy of this message
Sorting is definitely slower than going through once c or php. The speed of the algorithm is always more important than the language. There may be a slow down with php but it will always be O(1) and that is negligible. So unless you have only 2 items in the list where only 2 permutations are possible sorting will be slower. min() or max() are the functions to use if possible. for each is a language construct and should be having c like performance. C is not always faster. It's not a magic silver bullet to increase performance. Yes, you probably have fewer machine instructions on most things and don't get me wrong, I love c but if the algorithm is slower c can be slower than php. On Sun, 3 May 2015 11:10 pm Christoph Becker <cmbecker69@gmx.de> wrote: > German Geek wrote: > > > Sorting is always more expensive than going through the array once. > > That's a good point! > > > I would > > just iterate through once and keep track of the smallest or largest > element > > by storing the smallest or largest element in a temporary variable. There > > should really be a php function for that. > > Actually, there is: min(), which seems to be the simplest and most > efficient solution for Ron's task. > > -- > Christoph M. Becker >

« previous php.general (#324858) next »