Having some difficulty with some loops and wanted to see if anybody could shed some lite on it. I am looping thru one array (controlarray) comparing that to an element of a second array (myarray), if they match, I want to save some of the elements to a final array, but only the first arrays of the match. Here's what I have so far, by the way the controlarray has a count of 35 and the myarray has a count of 145 so I know both are populated.
for i= 0 to controlarray.count()
'?"VALUE OF I. . ."i
'?"VALUE OF CONTROLARRAY. . ."controlarray[i]
if controlarray[i]<> invalid 'VALID IF
for each bx in myarray
if myarray[y].bx = controlarray[i] 'COMPARE LOOP
while r < 5
?"MATCH. . . "
pinfo={
bx: myarray[r].bx
by: myarray[r].by
bt: myarray[r].bt
}
finalarray.Push(pinfo)
r=r+1
if r > 5
r=0
exit while
endif
end while 'R LOOP
else
y=y+1 'move to next myarray
end if 'COMPARE LOOP
end for
y=0
else 'INVALID
i=i+1
end if 'VALID IF
end for
Now, not completely sure what I am missing but as shown it kicks out after r reaches 5 as desired but it never rolls the controlarray or myarray to next number to continue. Not sure if it matters but not every myarray has 5 matching bx elements, the myarray is an array read from an array file structured like but with more elements than shown. The script checks to make sure the controlarray is valid, then compares the bx element to the controlarray. All works except once r reaches 5 it kicks out of all loops. If the myarray doesn't have 5 matches no problem but most will have more, I only want first 5 of each. Thanks
<?php
error_reporting(0);
$items=array (
0 =>
array (
'bx' => 'D100',
'by' => 'Dog',
'bt' => 'Brown',
),
1 =>
array (
'bx' => 'D100',
'by' => 'Dog',
'bt' => 'Black',
),
2 =>
array (
'bx' => 'D100',
'by' => 'Dog',
'bt' => 'white',
),
3 =>
array (
'bx' => 'C100',
'by' => 'Cat',
'bt' => 'white',
),
4 =>
array (
'bx' => 'C100',
'by' => 'Cat',
'bt' => 'Brown',
),