In a constructor of a object, I would like to be able to pass an int variable (representing a id to then fetch to database) or an array (when i already fetched to database)
I tried something like this:
__construct($var){
if(isset($var['id'])){ /*tried also if($var['id']) != '')*/
$this->id = $var['id'];
}else{
$this->id = $var;
}
}
The thing is that by passing a int value parameter as $var, it will enter to the first case on the if.
So how can i propper check that $var is an (asociative) array ?
You can use
is_int ($var)to check if it is an int andis_array ($var)if it is an array