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');
3
  • stackoverflow.com/questions/1074059/… Commented Dec 22, 2010 at 14:48
  • its better to use array_push() to add elements in an php array Commented Dec 22, 2010 at 14:50
  • See the second answer of the duplicate question. You question is not an exact duplicate but that answer is good for this one too. Commented Dec 22, 2010 at 14:51

2 Answers 2

2

I believe $array[] is more efficient.

Sign up to request clarification or add additional context in comments.

1 Comment

Turns out thats because i've seen it here : stackoverflow.com/questions/2431629/php-array-push-vs-myarray - do I delete my answer as it's a dup?
0

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

  • "better"
  • faster
  • readability

Only one of them is valid.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.