I found a solution:
This is my example-array:
$array = [2 => "two", 1 => "one", "four" => 4];
As you can see, there are strings and integers used as array-keys.
First of all I need to sort the array by its keys:
ksort($array);
Now the array looks like this:
$array = ["four" => 4, 1 => "one", 2 => "two"];
Now I can move the pointer to the end of the array and get the key (so I have the highest numeric key):
end($array);
$key = key($array);
I now increase the key by 1 and insert the value with the new key:
$key++;
$array[$key] = "three";
Now the key is saved in the variable $key and the array looks like this:
$array = ["four" => 4, 1 => "one", 2 => "two", 3 => "three"];
$key = 3;
That's it.
Now the complete code for all of you script-kiddies out there:
$array = [2 => "two", 1 => "one", "four" => 4];
ksort($array);
end($array);
$key = key($array);
$key++;
$array[$key] = "three";