Search the Community
Showing results for tags 'array conditional combine'.
-
Trying to build an array from elements taken from another array, which I thought would be easy but not so much. My first step is to create a $control that will be used in a loop later on. I am then looping thru an array file comparing an element's value to the $control. If the same, for testing I am sending it to browser. In code below, $control is already created. The array file I am looping thru has the following structure: $items=array ( 0 => array ( 'time' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', ), 1 => array ( 'time' => '201601221400', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', ), 2 => array ( 'time' => '201601221400', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.', ), Note: The number of 'time' elements vary as tho how many have the same value. In the example I posted this particular time element has 3 of the same value, some have more some have less. I want to loop thru the array file, compare the $control to the 'time' value, if equal it will echo to browser. I want the loop to continue for either as long as the $control and 'time' are equal or 5 is reached. for($i=0; $i< count($control); $i++){ foreach ($items as $item){ while (($items['time']==$control[$i]) || ($r < 5 )){ if ($r > 5){ echo "OUT. . ."."<BR>"; $r=0; }else{ $r=$r+1; echo $control[$i]." ". $r."<br>"; } } } } When this is ran, I get the first 5 values of the first 'time' but then nothing, it's not continuing to the next $control. Can somebody point out my error(s)? Thanks.