domwalton Posted February 17, 2010 Share Posted February 17, 2010 I have a large amount of legacy code to tidy up. There are lots of functions that return arrays, when only one item is needed. I don't really wish to go through and reverse engineer all the functions so rather then do this each time: $somevar = somefunction(); $iwantthis = $somevar['thisone']; It was be very useful to do something like: $iwantthis = somefunction()['thisone']; I just can't recall the correct syntax for this, or whether it is actually allowed in PHP? Link to comment https://forums.phpfreaks.com/topic/192366-syntax-for-function-result-array-as-variable/ Share on other sites More sharing options...
jl5501 Posted February 17, 2010 Share Posted February 17, 2010 As the function is returning an array, I think you will have to stick with picking the array element you want, after the function returns. I do not think you can assign a variable to one element of the returned array on the return. Link to comment https://forums.phpfreaks.com/topic/192366-syntax-for-function-result-array-as-variable/#findComment-1013649 Share on other sites More sharing options...
domwalton Posted February 17, 2010 Author Share Posted February 17, 2010 I fear you are probably correct. I guess I shall have to change all the functions, it's not very clever having them blindly return whole arrays of stuff - I think this stuff must have been written some time ago. Thanks you. Link to comment https://forums.phpfreaks.com/topic/192366-syntax-for-function-result-array-as-variable/#findComment-1013661 Share on other sites More sharing options...
trq Posted February 17, 2010 Share Posted February 17, 2010 This feature was suggested and declined. See here. Personally, I like the idea. I'm pretty used to it from Python. Link to comment https://forums.phpfreaks.com/topic/192366-syntax-for-function-result-array-as-variable/#findComment-1013663 Share on other sites More sharing options...
domwalton Posted February 17, 2010 Author Share Posted February 17, 2010 Thanks thorpe, yes it would seem logical to be able to do so. At least I know for sure now, so I can move on. Link to comment https://forums.phpfreaks.com/topic/192366-syntax-for-function-result-array-as-variable/#findComment-1013697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.