I would like to create two very alike arrays. The second array only has one more item then the first one...
So what I'm trying to achieve is:
$array_one = ('one', 'two', 'three');
$array_two = ('one', 'two', 'three', 'four');
Is there a function to do so? I've looked at things like array_push, array_shift, but those aren't functions meant to do this kind of behavior I think.
Any build in function to "push" one item on a copy of an array?
Try with:
$array_two = array_merge($array_one, array('four'));
or
$array_two = $array_one;
$array_two[] = 'four';
or
$array_two = $array_one;
array_push($array_two, 'four');
or
$array_two = $array_one + array('four');
or
$array_two = $array_one;
$array_two += array('four');
You can try
print_r($array_one + $array_two);
This will just add extra value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With