Jump to content

Use a returned array inline?


mkoga

Recommended Posts

yeah that would work. i was wondering if anyone had a trick to do it inline. i should probably explain what i'm doing.

 

consider:

$fileinfo = $this->input->files('file');

 

$fileinfo would then contain the info for an uploaded file named 'file'. however, it'd be nice if it were possible to do something like this:

$filename = $this->input->files('file')['name'];

 

i suppose i could convert $GLOBAL to an object, but that's just more work. if it's not possible, that's cool, just thought i'd ask.

 

if you only want to return the first item from the array returned by $this->input->files('file') use array_shift, eg:

$filename = array_shift($this->input->files('file'));

 

array_shift will remove the first item from the array and return its value.

Say $this->input->files('file') returned an array like so:

array (path, filename, filesize) you could use list to get the filename

list(,$filename,) = $this->input->files('file');

 

or create your own function which will return what ever item you want from the array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.