How to add elements to an empty array in PHP?

后端 未结 8 676
天命终不由人
天命终不由人 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:20

    Based on my experience, solution which is fine(the best) when keys are not important:

    $cart = [];
    $cart[] = 13;
    $cart[] = "foo";
    $cart[] = obj;
    

提交回复
热议问题