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/']
**No, there is no way to do that natively.**

You can, however:

1.- Store the unavoidable array instead of the string. Given PHP's limitation this is what makes most sense in my opinion.

Also, don't forget you can [unset()](http://php.net/unset)

2.- Use strpos() and friends to parse the string into what you need, as shown in other answers I won't paste here.

3.- Create a function.
I spent a great deal of last year researching advanced CSV parsing for PHP and I admit it would be nice to randomly seek at will on a file. One of my semi-deadend's was to scan through a known file and make an index of the position of all known \n's that were not at the beginning of the line. 

```
   //Grab and load our index
$index = unserialize(file_get_contents('somefile.ext.ind'));
//What it looks like
$index = array( 0 => 83, 1 => 162, 2 => 178, ....);

$fHandle = fopen("somefile.ext",'RB');
$randPos = rand(0, count($index));
fseek($fHandle, $index[$randPos]);
$line = explode(",", fgets($fHandle));

```

Tha's the only way I could see it being done anywhere close to what you need. As for creating the index, that's rudimentary stuff.

```
$fHandle = fopen('somefile.ext','rb');
$index = array();
for($i = 0; false !== ($char = fgetc($fHandle)); $i++){
      if($char === "\n") $index[] = $i;     
}

```