Which is the faster variable $ [] or array_push (variable $, $ newValue)?

What happens faster when adding variables to an array?

  • $ variable [] = $ newValue;
  • array_push (variable $, $ new_value);

and please indicate the difference between them, if any.

+5
source share
2 answers

http://www.php.net/manual/en/function.array-push.php#53289

The holder of Empy does not check, the variable is an array at first as array_push does. If array_push finds that the variable is not an array, it displays a warning message if E_ALL error reporting is enabled.

So, array_push is safer than [], while this is further modified by PHP developers.

$variable[] seems a lot faster:

http://www.php.net/manual/en/function.array-push.php#83388

, array_push() :

http://www.php.net/manual/en/function.array-push.php#84959

, . , , , .

+17

, .

ps: .

pps: :

  • ? - 2, - 6
  • ,
  • 1
+8

All Articles