You can then use that on the $results array to gain access to the next occurance in the array. This question already has answers here : Get next element in foreach loop (11 answers) Closed 9 years ago. So if you want to test this row against the next row in the array, a simple change to the format of the foreach will provide you with the key to the array. The foreach loop though iterates over an array of elements, the execution is simplified and finishes the loop in less time comparatively. 1, 3, 5, 7, 9, 11, 13, 15 I cant figure out how to make the number in the second paragraph increment by 2 with each loop. Here the variable count is initialized to a value of 1, then a while loop is started with the comparative expression count < 12. How to find the index of foreach loop in PHP The foreach construct provides the easiest way to iterate the array elements. Getting the next item in a python for loop. $wpdb->get_results returns an array of resultset rows and a foreach processes over an array, so the foreach does all the moving down an array, all you need to do is use the $row as the current row you are processing $results = $wpdb->get_results ( "SELECT * FROM interestclassĪdditional code as per your comment below. However, I want the number in the second paragraph to increment by 2 with each loop, e.g. How to fix it EDIT: based on the answers I will move the echo 'Total' stuff at the beginning of the next iteration instead of at the bottom of the current iteration.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |