I create a switch case where should be a different output based on the $v['domainrenew']['msetupfee'] variable and somehow I can't understand why is not working.
When I save and access the page I get a unexpected 'switch' (T_SWITCH) in error
Any idea how to fix this?
This is the switch I use:
switch($v['domainrenew']['msetupfee']){
case $v['domainrenew']['msetupfee'] == '-1' :
echo $v['domainrenew']['qsetupfee'];
break;
case $v['domainrenew']['msetupfee'] == '0' :
echo "Gratis";
break;
case $v['domainrenew']['qsetupfee'] == '0' :
echo "Gratis";
break;
default:
echo $v['domainrenew']['msetupfee'] ;
}
And the full context where I try to use the switch
$mydata = getDomainsPrice();
foreach($mydata as $k => $v)
{
$is_in_gtld = get_europa($k);
if($is_in_gtld == 1)
{
echo "<tr>
<td><span style=\"font-size: 16px !important;font-weight: 600;color: #1a202c;\"> $k </span></td>
<td class=\"dnone\" style=\"border-top: 1px dashed #e5e9f2;font-size: 14px;font-weight: 500;color: rgba(91, 88, 88, 0.9);\"> ".($v['domainregister']['msetupfee'] == '-1' ? '2' : '1')." </td>
<td style=\"border-top: 1px dashed #e5e9f2;font-size: 14px;font-weight: 500;color: rgba(91, 88, 88, 0.9);\">" .($v['domainregister']['msetupfee'] == '-1' ? $v['domainregister']['qsetupfee'] : $v['domainregister']['msetupfee']). $v['domainregister']['suffix'] . "</td>
<td style=\"border-top: 1px dashed #e5e9f2;font-size: 14px;font-weight: 500;color: rgba(91, 88, 88, 0.9);\">" .($v['domainrenew']['msetupfee'] == '-1' ? $v['domainrenew']['qsetupfee'] : $v['domainrenew']['msetupfee']). $v['domainrenew']['suffix'] . "</td> .
<td class=\"dnone\" style=\"border-top: 1px dashed #e5e9f2;font-size: 14px;font-weight: 500;color: rgba(91, 88, 88, 0.9);\">"
switch($v['domainrenew']['msetupfee']){
case $v['domainrenew']['msetupfee'] == '-1' :
echo $v['domainrenew']['qsetupfee'];
break;
case $v['domainrenew']['msetupfee'] == '0' :
echo "Gratis";
break;
case $v['domainrenew']['qsetupfee'] == '0' :
echo "Gratis";
break;
default:
echo $v['domainrenew']['msetupfee'] ;
}
"</td></tr>"
;}
}
My Answer:
$v['domainrenew']['qsetupfee'];
break;
case $v['domainrenew']['msetupfee'] == '1' :
echo $v['domainrenew']['qsetupfee'];
break;
default:
echo "No matching case found";
}
Make sure to remove the comparison operator (==) from the case statements and only use the variable value to evaluate the cases.
Rate this post
4 of 5 based on 7819 votesComments