Two array : Fee and Amount, have been formed as below based on MYSQL JOIN Clause and Table structure.
Array Fee
Array
(
[0] => Annual Fee-Disability Scholarship
[1] => Annual Fee-First rank Scholarship
[2] => Monthly Fee-First rank Scholarship
)
Array Amount
Array
(
[0] => 1000-20
[1] => 1000-10
[2] => 560-5
)
Array Fee contains the category of fee And assigned scholarship to each category
Array Amount contains the fee rate And the assigned scholarship percentage in each fee category.
I need to remove fee category and it's amount if this is already echoed.
Normally, using following PHP code:
$cat = array('Annual Fee-Disability Scholarship','Annual Fee-First rank Scholarship','Monthly Fee-First rank Scholarship');
$amount = array('1000-20','1000-10','560-5');
foreach (array_combine($cat, $amount) as $cat => $amount){
$cat_ry = explode('-', $cat);
$amount_ry = explode('-', $amount);
$fee_cat = $cat_ry[0];
$fee = $amount_ry[0];
$sch_cat = $cat_ry[1];
$sch = $amount_ry[1];
echo "
<tr>
<td>$fee_cat</td>
<td>$fee</td>
</tr>
<tr>
<td>$sch_cat</td>
<td>$sch</td>
</tr>";
}
following table format is echoed.
PHP Fiddle - complete code and result
Here Annual Fee category is being duplicated, cause two scholarships has been associated with this fee category.
So my requirement is to remove duplicate fee category and its related amount. Required Output
So I try: not echo fee category if it is already echoed
$fee_cat = "";
//code
//...
if($cat_ry[0] != $fee_cat){
$fee_cat = $cat_ry[0];
//code
//...
}
but here, with duplicated fee category another scholarship First Rank Scholarship is also removed


