SiC_Goat Posted October 15, 2008 Share Posted October 15, 2008 I'm aware that array is a language construct and not a function, however I'm curious to the extend of the T_DOUBLE_ARROW token [read: =>] and it's usability in user functions. Is it possible to define a function that accepts 'k => v' key pair sets in the same manner of array? I'm trying to avoid having to 'foo ( array ( bar1 => bar2, bar3 => bar4 ) )' every time I want to call this specific function. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 15, 2008 Share Posted October 15, 2008 you could possibly use a foreach loop http://us3.php.net/manual/en/control-structures.foreach.php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 15, 2008 Share Posted October 15, 2008 Can you give us a hint as to what the function is supposed to look like? Code? If we see what you're trying to do, perhaps we can help you better. Ken Quote Link to comment Share on other sites More sharing options...
SiC_Goat Posted October 20, 2008 Author Share Posted October 20, 2008 I want to do something like function demoStub ( KeyPair $pair ) { foreach ( $pair as $k => $v ) { // magic } } demoStub ( "red" => "fish", "blue" => "fish", "one" => "fish", "two" => "fish" ); I'm fairly certain at this point that it is impossible to construct such a function as array is a language structure rather than a function type. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 wrap the word array around your key/pairs like so: <?php function demoStub ( $pairs ) { foreach ( $pairs as $k => $v ) { print "$k: $v<br />"; } } demoStub ( array("red" => "fish", "blue" => "fish", "one" => "fish", "two" => "fish") ); ?> Quote Link to comment Share on other sites More sharing options...
SiC_Goat Posted October 20, 2008 Author Share Posted October 20, 2008 wrap the word array around your key/pairs like so: That is exactly what I was trying to work around. It just glares at me with dirty eyes Quote Link to comment Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 why are you trying to avoid it? Quote Link to comment 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.