Better array pushing
In any language, you’ll often find yourself working with arrays. PHP offers a couple methods for adding items to them. Say you have an array:
$arrayvals = array("elton", "sam");
and you want to add the value, “shaun” to it. You can either do:
$arrayvals[] = "shaun";
or you can do:
array_push($arrayvals, "shaun");
So which is better, or does it even matter? The answer is the first one, $arrayvals[]=”shaun”;, because according to the php manual, there is no overhead of calling a function with this method. A minor difference, but when writing web apps, every line you write is potentially called millions of times per second so you don’t want to be wasting cycles for no reason. Is there a point to array_push then? Remember that array_push allows adding multiple values at once so it’s easier to do:
array_push($arrayvals, "shaun", "corey", "chris");
