I have
$whitelist = array ("a", "b", "c", "d");
a global whitelist of allowed values of a certain $_POST variable. I use the following expression to obtain an enlarged whitelist with a certain extra value ("e")
array_merge($whitelist, array("e"))
(I feed this to a whitelisting function). But it seems rather complicated.
I am wondering if there is a better way to do this? I.e. I am looking for an expression returning an array with an added element.
I am aware of the following two constructions
$whitelist[] = "e";
and
array_push($whitelist, "e");
but both are procedural, modify the original array and neither of them could be used in an expression.
A possible expression would also be
$whitelist + array((max(array_keys($whitelist))+1)=>"e")
but it is even more cumbersome than the array_merge method.