php array problem ..need expert
- by user295189
I have tried this in another post but trying my luck again. My current array that I am making produce a different result than I am wanting.
I want to have this kind of out put
Row: 0: Column: 1: ID 1
Row: 1: Column: 1: ID 1
Row: 0: Column: 2: ID 2
Row: 1: Column: 2: ID 2
Row: 2: Column: 2: ID 2
Row: 3: Column: 2: ID 2
Row: 0: Column: 3: ID 3
Row: 1: Column: 3: ID 3
As you can see the Rows and columns change based on the ID. So if the ID is same it just go to next row in the same column. However if id is changed it goes to next column and rows start.
Currently I my code looks like this
for($i=0;$i<count($pv->rawData); $i++) {
$relative=0;
$relativeTypeID = -1;
if ($pv->rawData[$i]->relativeTypeID != $relativeTypeID) {
$relativeTypeID = $pv->rawData[$i]->relativeTypeID;
$iTypeCount++;
}
if(!empty($pv->rawData[$i]->description)) {
$pv->results[$i][$iTypeCount][0] = $pv->rawData[$i]->description;
echo "Row: ".$i.": Column: ".$iTypeCount.": ID".$relativeTypeID." <br>";
}
}
It gives me the following output
Row: 0: Column: 1: ID1
Row: 1: Column: 2: ID1
Row: 2: Column: 3: ID2
Row: 3: Column: 4: ID2
Row: 4: Column: 5: ID2
Row: 5: Column: 6: ID2
Row: 6: Column: 7: ID2
Row: 7: Column: 8: ID2
Row: 8: Column: 9: ID2
Row: 9: Column: 10: ID2
Row: 10: Column: 11: ID2
Row: 11: Column: 12: ID2
Row: 12: Column: 13: ID2
….
….
As you can see the Row and Columns are changing but not with ID number.
I appreciate your help
Thanks