mkoga Posted April 1, 2008 Share Posted April 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/ Share on other sites More sharing options...
ansarka Posted April 1, 2008 Share Posted April 1, 2008 //$this->getList() returns an array $item1 = $this->getList(); now $item1 will contain the array you can use $item1[0]; Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/#findComment-506258 Share on other sites More sharing options...
mkoga Posted April 1, 2008 Author Share Posted April 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/#findComment-506262 Share on other sites More sharing options...
wildteen88 Posted April 1, 2008 Share Posted April 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/#findComment-506676 Share on other sites More sharing options...
mkoga Posted April 1, 2008 Author Share Posted April 1, 2008 thanks, i knew about that one. the trick would be to return any key you wanted by index. Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/#findComment-506916 Share on other sites More sharing options...
wildteen88 Posted April 2, 2008 Share Posted April 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/98943-use-a-returned-array-inline/#findComment-507744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.