I want to extract array of data multiple times by using foreach()
loop from database in php, I have one scenario given below.
Note $results
is containing database data :
$values = array(10,20,30,40);
$datas = $results;
foreach($values as $value) {
//some operations
foreach($datas as $data)
{
$time = $data->time;
// some operation
}
}
Here by doing DB-query I am extracting these data to "$results"
1528126233440,41602,48914,98,124,0,0,0
1528126248393,41602,48914,98,124,0,0,0
1528126251809,41602,48914,98,124,0,0,0
1528126256843,41602,48914,98,124,0,0,0
I have two different arrays
$values = array(10,20,30,40) // used for external loop
$datas = $results //used for internal loop
where as "$reasults" contains the database data.
lets say
for 1st iteration of external loop and when it execute internal loop I need this value [ [1528126233440, 41602], [1528126248393, 41602], [1528126251809, 41602], [1528126256843, 41602] ]
for 2nd iteration of external loop and wehen it execute internal loop I need this value [ [1528126233440, 98], [1528126248393, 98], [1528126251809, 98], [1528126256843, 98] ]
like this..
so I my case the first iteration of external loop I am able to print [ [1528126233440, 41602], [1528126248393, 41602], [1528126251809, 41602], [1528126256843, 41602] ]
when it comes to the 2nd iteration of external loop the internal loop is not processing.
I need in each iteration of external foreach()
loop the inner foreach() loop should run every time**.
But in my case for the first iteration the external loop is working, when it comes to second iteration of external loop at that time the second loop is not working.
Any suggestion will great help for me
Thank you