Php array

Anyone can explain about follwoing code

if(obj[‘B’] [posCnt] [‘POSITION’]==sr)

If you want the best explanation, post the rest of the code. Basically it is saying if the value of obj[‘B’] [posCnt] [‘POSITION’] is sr then do what follows right after this code.

I am posting my rest code…[php]
switch(obj[‘B’][posCnt][‘QUOTA_FLAG’]) {
case ‘L’:
quotaClass = “class=‘ldy’”;
disabled = “disabled=‘disabled’”;
break;
case ‘6’:
disabled = “disabled=‘disabled’”;
quotaClass = “class=‘vip’”;
break;
case ‘4’:
disabled = “disabled=‘disabled’”;
quotaClass = “class=‘mdq’”;
break;
case ‘M’:
disabled = “disabled=‘disabled’”;
quotaClass = “class=‘mmdq’”;
break;
}

switch(obj[‘B’][posCnt][‘SEAT_TYPE’]) {
case ‘S’:
if(quotaClass=="") {
quotaClass = “class=‘slp’”;
seatType=‘S’;
break;
}
var chk = “”;
var bgcolor=’’;
switch(obj[‘B’][posCnt][‘TEMP_SEAT_STATUS’]) {
case ‘A’:
chk = “<input style=‘cursor: pointer’ “+quotaClass+“type=‘checkbox’ name=’”+sr+”’ id=’”+sr+"’ value=’"+obj[‘B’][posCnt][‘SEAT_NO’]+"’ seattype=’"+seatType+"’ onchange=allocate(’"+seatType+"’) “+disabled+” />";
break;
case ‘B’:
if(obj[‘B’][posCnt][‘PASSENGER_SEX’]==‘M’) {
bgcolor=‘background-color:red;color:#FFFFFF’;
} else if(obj[‘B’][posCnt][‘PASSENGER_SEX’]==‘F’) {
bgcolor=‘background-color:blue;color:#FFFFFF’;
} else {
bgcolor=’’;
}
chk = “Booked”;
//quotaClass = “class=‘book’”;
break;
case ‘L’:
chk = “”;
quotaClass = “class=‘lck’”;
break;
}
case ‘4’:
disabled = “disabled=‘disabled’”;
quotaClass = “class=‘mdq’”;
break;
case ‘M’:
disabled = “disabled=‘disabled’”;
quotaClass = “class=‘mmdq’”;
break;
}
switch(obj[‘B’][posCnt][‘SEAT_TYPE’]) {
case ‘S’:
if(quotaClass=="") {
quotaClass = “class=‘slp’”;
seatType=‘S’;
break;
}
var chk = “”;
var bgcolor=’’;
switch(obj[‘B’][posCnt][‘TEMP_SEAT_STATUS’]) {
case ‘A’:
chk = “<input style=‘cursor: pointer’ “+quotaClass+“type=‘checkbox’ name=’”+sr+”’ id=’”+sr+"’ value=’"+obj[‘B’][posCnt][‘SEAT_NO’]+"’ seattype=’"+seatType+"’ onchange=allocate(’"+seatType+"’) “+disabled+” />";
break;
case ‘B’:
if(obj[‘B’][posCnt][‘PASSENGER_SEX’]==‘M’) {
bgcolor=‘background-color:red;color:#FFFFFF’;
} else if(obj[‘B’][posCnt][‘PASSENGER_SEX’]==‘F’) {
bgcolor=‘background-color:blue;color:#FFFFFF’;
} else {
bgcolor=’’;
}
chk = “Booked”;
//quotaClass = “class=‘book’”;
break;
case ‘L’:
chk = “”;
quotaClass = “class=‘lck’”;
break;
}
}[/php]

The line of code you originally asked about is not even in the full code you posted.

Did you mean to nest those switches?

i(obj[‘B’][posCnt][‘POSITION’] == sr) is a multidimensional array. That entire bit isn’t PHP though, its javascript, looks like some kind of validation script for some sort of transportation booking site. It works the same way as in php, same concepts, its just accessing each part of the array directly.

Sponsor our Newsletter | Privacy Policy | Terms of Service