How to add elements to an empty array in PHP?

后端 未结 8 678
天命终不由人
天命终不由人 2020-11-22 12:07

If I define an array in PHP such as (I don\'t define its size):

$cart = array();

Do I simply add el

8条回答
  •  臣服心动
    2020-11-22 12:17

    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:

    $cart = array(13, "foo", $obj);
    

提交回复
热议问题