I iterate over the array of arrays and access the value of the array through associative keys, this is a piece of code. Note: I never iterate over a full array, but only with window 10.
//extract array from a db table (not real code) $array = $query->executeAndFetchAssociative; $window_start = 0; for($i = $window_start; $i<count($array) && $i<$window_start+10; $i++) echo($entry["db_field"]);
This is a kind of page for the web interface. I get windows_start value and display hte next 10 values.
Conceptual implementation:
- Get windows_start number
- Start the loop by entering the window_start-TH array of the external array
- Display the value of an internal array field using an associative index
- Move to window_start + 1
Internal arrays have about 40 fields. An external array can grow dramatically because it contains a database table. Now I see that as the external array grows, executing on windows 10 takes more and more time.
I need a “performance code” for my code:
If I enter the values of internal arrays using a numeric key, can I have better performance? In general, faster access to the values of an array with a numerical index than handling an associative index (string)?
How to enter a random entry ($ array [random_num]) of an array of length N? O (N), O (N / 2), e.g.
Finally, does the iteration speed over the array depend on the length of the array? I mean, I always repeat 10 elements of the array, but how does the length of the array affect my iteration with a fixed length?
Thanks Alberto
source share