$result = $this->db->query($query)->result_array();
if($result[9]['b_code'] != FALSE)
{
$result_array = array(
'0' => $result[0]['b_code'],
'1' => $result[1]['b_code'],
'2' => $result[2]['b_code'],
'3' => $result[3]['b_code'],
'4' => $result[4]['b_code'],
'5' => $result[5]['b_code'],
'6' => $result[6]['b_code'],
'7' => $result[7]['b_code'],
'8' => $result[8]['b_code'],
'9' => $result[9]['b_code']
);
return $result_array;
}
else
return FALSE;
It extracts 10 data in rows and make it a new array as $result_array;
Sometimes, it won’t have 10 results and may extract 5 or 8.
So, I wanna check wether there is a value for last one, which is $result[9][‘b_code] or not.
Should I use isset?
Yes,
issetDocs is the right language construct if you want to test if a value is set (e.g. set and notNULLDocs).In your particular case you can also check the length of
$result, that is done withcountDocs:Some example code with
isset:Note that in this example we’re preventing to repeat ourselves 10 times only to copy each
b_codeelement. Instead, this is done with array mapping, seearray_mapDocs.A probably more readable variant, this time with
count:This variant is making use of
foreachDocs to prevent assigning 10 elements one by one.