3

I have an array encoded in UTF-8, sorta like this:

Array
(
[0] => אלף
[1] => בית
[2] => גימל
[3] => דלת
[4] => הא
[5] => ואו
)

Is it possible to leave the 0 array item empty and start the array at 1? I sorta wanna nudge everything over, and the array would then look like this:

Array
(
[0] => 
[1] => אלף
[2] => בית
[3] => גימל
[4] => דלת
[5] => הא
[6] => ואו
)

Thanks!

5
  • What do you mean by empty? A zero-length string? Commented May 26, 2013 at 8:13
  • Yeah, a zero length string. Commented May 26, 2013 at 8:19
  • Then doesn't @Dave Chen's answer work for you? I mean it should do what you're asking for, I'd say as well for your concrete case array_unshift looks like the right tool. Commented May 26, 2013 at 8:19
  • Thanks! It does work for me. But now that I'm dumping out other arrays it seems that really I needed to move the array in the reverse order (meaning that the 0 item is already empty, and I need to shift everything downward to fill the 0 item. Commented May 26, 2013 at 8:28
  • 1
    I suggest to take a little read on the PHP manual and all it's glory array functions. It's a full tool-set so get a bit into it: php.net/arrays / php.net/ref.array Commented May 26, 2013 at 9:06

1 Answer 1

5

Use array_unshift, example:

<?php

$arr=array(1,2,3);
array_unshift($arr,null);

print_r($arr);

?>

Prints Array ( [0] => [1] => 1 [2] => 2 [3] => 3 )

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.