• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Basic PHP] Treat function or method call as an array?

#1
[eluser]janogarcia[/eluser]
I have these values

Code:
$CI->config->item('returns_indexed_array');
$CI->config->item('returns_index');

This works...

Code:
$array = $CI->config->item('returns_indexed_array');
$index = $CI->config->item('returns_index');

$value = $array[$index];

...but, what if I don't want to create those temporary variables $array and $index? Is it possible to get the value in one shot?

This wouldn't work... Any simple workaround? Am I missing something?
Code:
$value = $CI->config->item('returns_indexed_array')[$CI->config->item('returns_index')];

Found in stack overflow:
Quote:Unfortunately, you cannot treat function return values as arrays in PHP. You have to assign the value explicitly.


Messages In This Thread
[Basic PHP] Treat function or method call as an array? - by El Forum - 01-08-2010, 09:23 AM
[Basic PHP] Treat function or method call as an array? - by El Forum - 01-08-2010, 09:30 AM
[Basic PHP] Treat function or method call as an array? - by El Forum - 01-08-2010, 09:38 AM
[Basic PHP] Treat function or method call as an array? - by El Forum - 01-08-2010, 09:45 AM
[Basic PHP] Treat function or method call as an array? - by El Forum - 01-09-2010, 03:28 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.