J
J
jazzus2019-05-11 13:46:42
Laravel
jazzus, 2019-05-11 13:46:42

How to add values ​​to an array using the Arr helper?

Initial data

$array = [];
$one = 1;
$two = 2;

You need to add values ​​to array like this
if (true) {
    $array = Arr::add($array,'0',$one);
}
 if (true) {
    $array = Arr::add($array,'1',$two);
}

But, so that the key does not need to be affixed by hand. As a result, you need to get:
dd([$one, $two]);
// или с индексом 0
dd([$two]);

Is it possible to do this with the Arr helper and how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vism, 2019-05-11
@jazzus

it can be done by PHP
why Arr wrap native methods
array section on php.net

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question