Not sure if this is possible. For example:
$color = isset($product['color']) ? $product['color'] : '';
$size = isset($product['size']) ? $product['size'] : '';
$qty = isset($product['qty']) ? $product['qty'] : '';
***
***
I use isset()
pretty much everywhere I need to get a value from array that I am not sure if its set. I am using my own custom framwork so I was wondering if I can add some kind of way to check automatically if its set or not.
So I want something like this:
//if its not set, do not throw warning message just return blank
$color = $product['color'];
$size = $product['size'];
$qty = $product['qty'];
Basically similar to what PHP magic function __isset
does for the class but I need it for any array that is not a class.
I added a function to my BaseController
that is used in every controller but it is still an extra function call:
$color = $this->isSet($product, 'color', '');
$size = $this->isSet($product, 'size', '');
$qty = $this->isSet($product, 'qty', '');
and function:
public function isSet(array $data, $key, $return) {
return isset($data[$key]) ? $data[$key] : $return;
}
My question is, is there a better way of doing this without functions?