Search the Community
Showing results for tags 'multidimensional associative'.
-
I may have gotten carried away trying to make my project ultra efficient... Originally, I wrote my application to repeatedly grab the same data set from mySQL with each php module. The data is used in a variety of ways, so I get the full mySQL data record and then chop & process it within the php module rather than modifying the query over and over again. I thought it would be great to get data once, stuff it all into a multidimensional array, and transfer the array from module to module to increase speed (RAM is faster than drive access, right?) As I extracted full data sets with recursiveIteratorIterator(), I realized that once I obtained the needed data subset I could break the loop because the balance of the data was unneeded -- so I switched to nested foreach loops to grab data from the array and added a break when the data subset was extracted. So now I am on the third version of the same code and I am finding that var_dump($array) has a lengthy pause after about 150 records. When I display the data using echo or print_r, the nested foreach loops stop at about the point of the var_dump pause. The array size of my current query is 102KB. Questions: I like the idea of cutting the processing when the data search has done it's job before the end of record, but am I really saving time or resources? Is it really a better idea to create a large array and pass it between modules or is grabbing the data from mySQL (perhaps cached?) a better choice? What is causing the pause in var_dump? Am I running out of RAM, perhaps going to virtual ram on my computer? Is there a way to assign memory to the array? Why is the nested foreach commands stopping output prematurely? In terms of efficiency balanced by practicality, what is the best approach? Code - This version displays the full record without breaks: foreach ($rows as $key => $row) { foreach ($row as something => $else) { foreach ($else as $k => $V) { echo "row(",$key,") "," field[",$something,"] ",$k ,": ", $v, "<br/>"; } } }
-
Does anyone know how to do this? Use one multi- dimensional associative array to store the questions, choices and answers for this quiz. Use a nested foreach loop to display the questions and choices. Create and use a simple function to calculate the percentage based on the number correct out of the total number of questions.