Can this be done in 1 line with PHP?
It would be great if that were possible:
$out = array("foo","bar"); echo $out[0];
Sort of:
echo array("foo","bar")[0];
Unfortunately this is not possible. Is this possible?
Therefore, I can do this, for example, in 1 line:
echo array(rand(1,100), rand(1000,2000))[rand(0,1)];
So let's say I have this code:
switch($r){ case 1: $ext = "com"; break; case 2: $ext = "nl"; break; case 3: $ext = "co.uk"; break; case 4: $ext = "de"; break; case 5: $ext = "fr"; break; }
It would be much easier to do this as follows:
$ext = array("com","nl","co.uk","de","fr")[rand(1,5)];
source share