In Java you can get an element from an array directly from the method call, like this:
System.out.println(PrintArrayOfStrings()[0]);
Is there any similar way to do this in PHP?
echo PrintArrayOfStrings()[0]; // Does not work!
Or do I always have to use a variable that first gets the array and then I use that variable to get the element?
$array = PrintArrayOfStrings();
echo $array[0]; // Works!
is not possible/supported in PHP.
You can do it as you wrote:
or do it like this, if you want to have it on one line:
so then, you can use: