Php

Asked • 05/15/19

How to add elements to an empty array in PHP?

If I define an array in PHP such as (I don't define its size): <!-- language: lang-php --> $cart = array(); Do I simply add elements to it using the following? <!-- language: lang-php --> $cart[] = 13; $cart[] = "foo"; $cart[] = obj; Don't arrays in PHP have an add method, for example, `cart.add(13)`?

1 Expert Answer

By:

Siva J. answered • 09/25/21

Tutor
5.0 (449)

Adjunct Faculty who taught Web App Development courses using PHP

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.