I'm coming from C++ and learning PHP at the moment.
When using arrays with key assignment I noticed that if you add an element to the array without specifying the key it'll auto-assign it.
Is that undefined behavior or PHP handles that?
$var = array( 1 => "The", 2 => "Rabbit", 3 => "Hole" );
$var = "Goes"; //add elements without specifying the key
$var = "Down";
Array (  = The  = Rabbit  = Hole  = Goes  = Down )
$var2 = array ( 'a' => "All", 'b' => "The", 'c' => "Single" );
$var2 = "Ladies";
Array ( [a] = All [b] = The [c] = Single  = Ladies )
The behaviour is defined by the PHP specification. In case you insert a new element without specifying a key:
If the array already contains at least one integer key, the largest of these keys will be taken, incremented, and used as a new key upon insertion.
If the array does not contain an integer key, the automatically assigned key will be 0.
See the PHP documentation.