0

Possible Duplicate:
array_push() vs. $array[] = … Which is fastest?

Is it better to use [] or array_push() to add to an array in PHP?

I always use array_push(), but only because it seems proper.

$array = array();

array_push($array, array('1', '2', '3'));

// or

$array[] = array('1', '2', '3');
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Josh
  • 12,218
  • 10
  • 71
  • 117

2 Answers2

2

I believe $array[] is more efficient.

piddl0r
  • 2,461
  • 1
  • 23
  • 35
  • Turns out thats because i've seen it here : http://stackoverflow.com/questions/2431629/php-array-push-vs-myarray - do I delete my answer as it's a dup? – piddl0r Dec 22 '10 at 14:50
0

When comparing alternative syntax constructs, there are multiple attributes to take into consideration:

  • "better"
  • faster
  • readability

Only one of them is valid.

mario
  • 141,508
  • 20
  • 234
  • 284