fbc
4 months ago

How do you add an element to an array without a key value?

Posted 4 months ago by fbc

I've been using the ARR helper to get this done but the problem is that I just want to add to the array without having to specify the key value..

$arr = []
$arr = Arr::add($arr,0,'Bob');
$arr = Arr::add($arr,0,'Larry');

only gets me:

array:1 [▼
  0 => "Bob"
]

in order to get Larry I have to do:

$arr = []
$arr = Arr::add($arr,0,'Bob');
$arr = Arr::add($arr,1,'Larry');

So I basically have to number them. i tried append instead of add but it didn't exist. Any other why to get this done??

Please sign in or create an account to participate in this conversation.