Jump to content

Use a returned array inline?


mkoga

Recommended Posts

Does anyone know of a way to use a returned array inline?

 

For example:

//$this->getList() returns an array
$item1 = $this->getList()[0];

 

Don't know if this or something like it is possible, but it'd be pretty cool.

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.