I have this function below:
public function set_partial($array)
{
if (is_array($array)) {
foreach ($array as $each) {
self::$_partials[$each[0]] = array('view' => $each[1], 'data' => $each[2]);
}
}
}
In self::$_partials, ‘data’ isn’t required. So how do I keep my code simple while allowing data to be null? Right now, if data isn’t provided, then I get an offset error.
You can check to see if
each[2]isset. If it is, then set the variable, otherwise make it null: