I asked this question before, [Here](https://stackoverflow.com/questions/264441/does-a-native-php-5-function-exist-that-does-the-following-in-1-line) however I think I presented the problem poorly, and got quite a few replies that may have been useful to someone but did not address the actual question and so I pose the question again.

Is there a single-line native method in php that would allow me to do the following.
Please, please, I understand there are other ways to do this simple thing, but the question I present is does something exist **natively in PHP** that will **grant me access to the array** values directly **without having to create a temporary array**.

```
$rand_place = explode(",",loadFile("csvOf20000places.txt")){rand(0,1000)};

```

This is a syntax error, however ideally it would be great if this worked!

Currently, it seems unavoidable that one must create a temporary array, ie

**The following is what I want to avoid:**

```
$temporary_places_array = explode(",",loadFile("csvOf20000places.txt"));
$rand_place = $temporary_places_array[rand(0,1000)];

```

Also, i must note that my actual intentions are not to parse strings, or pull randomly from an array. **I simply want access into the string without a temporary variable**. This is just an example which i hope is easy to understand. There are many times service calls or things you do not have control over returns an array (such as the explode() function) and you just want access into it without having to create a temporary variable.

**NATIVELY NATIVELY NATIVELY, i know i can create a function that does it.**
['https://Stackoverflow.com/questions/267534', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/34561/']
There is no native PHP method of doing this.

You could make a function like this:

```
function array_value($array, $key) {
    return $array[$key];
}

```

And then use it like this:

```
$places = "alabama,alaska,arizona .... zimbabway"; 
$random_place = array_value(explode(",", $places), rand(0, 1000));

```
If it's memory concerns, there are other ways of going about this that don't split out into an array. But no, there is nothing builtin to handle this sort of situation.

As an alternative, you might try:

```
$pos = 0;
$num = 0;
while(($pos = strpos($places, ',', $pos+1)) !== false) {$num++;}
$which = rand(0, $num);
$num = 0;
while($num <= $which) {$pos = strpos($places, ',', $pos+1);}
$random_place = substr($places, $pos, strpos($places, ',', $pos+1));

```

I havn't tested this, so there may be a few off-by-one issues in it, but you get the idea. This could be made shorter (and quicker) by cacheing the positions that you work out in the first loop, but this brings you back to the memory issues.