How to cast variable to array
You can cast a variable to an array by using:
$var = (array)$arr;
Alternatively you could use settype
:
settype($a, "array");
For expliciting the variable type. It's exactly the same as what happens with a typecast behind the scenes. (More useful for group-wise typecasting e.g. in loops.)
$a = (array) $v;
is the answer.
I would write your could snippet like this (short and you read it and know exactly what is happening):
$a = is_array($v) ? $v : array($v);