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,738
  • 21
  • 105
  • 131
Josh
  • 12,448
  • 10
  • 74
  • 118

2 Answers2

2

I believe $array[] is more efficient.

piddl0r
  • 2,431
  • 2
  • 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
  • 144,265
  • 20
  • 237
  • 291