PHP adds the beginning of an array without reordering

I tried to find the answer to my question, but could not find the one that did this without changing the numerical indices.

Is there a way to add a string to the beginning of an array without reordering keys (numeric keys) without using a loop?

thank

EDIT:

I will try to explain the scenario. (I am using CodeIgniter).

I have an array that is used throughout my application. This array is also used to create a drop-down list and check these drop-down list values ​​in the form that I have. What I would like to do is insert an empty value at the beginning of the array so that by default I get an empty parameter.

So from this

1 => Hello
2 => World

to

'' = > ''
1 = >
2 = >

+5
1

, , array_unshift .

, , :

$x = array(1 => 1, 2 => 2, 3 => 3); 
$y = array(1101 => 123);
var_dump( $y + $x );

/* Output:
array(4) {
  [1101]=>
  int(123)
  [1]=>
  int(1)
  [2]=>
  int(2)
  [3]=>
  int(3)
}
*/

, , foreach .

:

$x = array(1 => "Hello", 2 => "Welt"); 
$y = array("" => "");

var_dump($y + $x);

/*
array(3) {
  [""]=>
  string(0) ""
  [1]=>
  string(5) "Hello"
  [2]=>
  string(4) "Welt"
}
*/
+8

All Articles