Passing multiple parameters to a function in a variable

This topic contains 1 reply, has 2 voices, and was last updated by  Dave Wyatt 2 years, 7 months ago.

  • Author
  • #32491


    Say i have a function

    function test($a, $b)
    And i have
    $x = "a b"
    I cant pass it
    > test $x 
    but i can pass it 
    > test a b
    Is there a way to pass multiple params through the one variable?
    $x = "a b"
    test $x
  • #32492

    Dave Wyatt

    Yes, but not as a single string like that. Instead, you would have an array or a hashtable for your variable, and you would use a technique called Splatting. That looks like this:

    $array = 'a', 'b'
    test @array

    You can get all the gritty details in the about_Splatting help file. 🙂

You must be logged in to reply to this topic.