0

I got this:

$arr = array();
$arr[0] = "Test";
$arr[1] = "Bla";
$arr[2] = "Boo";

Now I would like to add "SO" to this array, but in the start of the array, the [0] index. But without removing the current, so it should instead move the rest of the content, so "Test" gets to be [1] and Bla is [2] and Boo is [3].

How can this be done?

1
  • 2
    array_unshift($arr, 'SO'); Commented Dec 4, 2012 at 17:03

2 Answers 2

2

I believe you want to make use of array_unshift()

0
1

Look at the array manipulation functions. array_unshift() should do what you want. Other similar functions are array_shift(), array_pop(), and array_push()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.