
Why to Fetch Database Records into an Array in Core PHP?
In my last post here I explained "How to Fetch Database Records into a Multidimensional Array using Core PHP". But I left the question unanswered and did not provide details about why do we need to store database data in a multidimensional array while we are already storing the data in associative array through fetch_assoc() function. Let me explain my point In our last code we are storing and retrieving name and email thorough $row['name'], $row['email'] respectively. Then we are again saving this data in $data[0][$i] and $data[1][$i] respectively in a while loop. The question is why we are storing name, email data in $data array. As this is a temporary storage and we do not need it as we can use $row array instead? Here is the reason Suppose we have employee data in our database as "name", "email", "phone", "salary", "loan-amount", "time_period". As data shows employees have taken loans for a fixed period of time. Now our task is to calculate compound interest for each employee and w
Continue reading on Dev.to Webdev
Opens in a new tab

