lighton Posted October 13, 2007 Share Posted October 13, 2007 i came across this whilst browsing the php docs function rnatsort ( &$array = array() ) { what does the & do before the $array? ??? Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/ Share on other sites More sharing options...
esukf Posted October 13, 2007 Share Posted October 13, 2007 Pass the array to the function by reference. http://uk.php.net/language.references.pass Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/#findComment-368645 Share on other sites More sharing options...
redarrow Posted October 13, 2007 Share Posted October 13, 2007 little example <html> <body> <?php function hi(&$a) { echo $a . " redarrow.<br />"; } $b="My name is"; hi($b); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/#findComment-368667 Share on other sites More sharing options...
Rithiur Posted October 13, 2007 Share Posted October 13, 2007 Here's a better example of references. In the previous one, it doesn't really matter whether it's passed by reference or not. <?php $b = 'foo'; function makebar(&$arg) { $arg = 'bar'; } makebar($b); echo $b; // will output 'bar'. ?> Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/#findComment-368670 Share on other sites More sharing options...
lighton Posted October 16, 2007 Author Share Posted October 16, 2007 thanks for the response are you saying (in essence) it means you dont have to return any values from the function? Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/#findComment-370547 Share on other sites More sharing options...
jscix Posted October 16, 2007 Share Posted October 16, 2007 Oh that's cool, I didn't know php could do that... this is similar to 'out' in C# eh? public Foo(out string bar) { bar = "Bar"; } Quote Link to comment https://forums.phpfreaks.com/topic/73097-sending-an-array-to-a-function/#findComment-370568 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.