If I define an array in PHP such as (I don't define its size):
$cart = array();
Do I simply add elements to it using?:
cartData[] = 13;
cartData[] = "foo";
cartData[] = obj;
Don't arrays in PHP have a add method, i.e. cart.add(13)?
up vote
3
down vote
favorite
1
|
|||
|
up vote
9
down vote
accepted
|
Both array_push and the method you described will work.
Is the same as:
|
||
|
up vote
3
down vote
|
Its better to not use array_push and just use what you suggested. The functions just add overhead.
|
||
|
up vote
1
down vote
|
It's called array_push: http://il.php.net/function.array-push |
||
|
up vote
0
down vote
|
You can use array_push. It adds the elements to the end of the array, like in a stack. You could have also done it like this:
|
|||
|