title: How can I pass a dynamic amount of attributes passed to a function?
body: <p>I have a function that uses another function as parameter.
  Just like this: </p>
  
  <pre><code>function myFunc($variables, $functionHelloWorld) {
       extract ($variables, EXTR_OVERWRITE); /* now I have a variable for each array item*/
       $functionHelloWorld($fruit,$color);
  });
  </code></pre>
  
  <p>And, using "myFunc()", I have this:</p>
  
  <pre><code>myFunc(array("fruit" =&gt; "banana","color" =&gt; "yellow"), function($fruit, $color) {
     echo "My fruit is: ".$fruit.". And my color is: ".$color;  
  });
  </code></pre>
  
  <p>Ok. It works!
  But, supose I would like to add a new parameter to this called function. Just like this:</p>
  
  <pre><code>myFunc(array("fruit" =&gt; "banana","color" =&gt; "yellow", "farm"=&gt;"My farm name"), function($fruit, $color, $farm) {
       echo "My fruit is: ".$fruit.". And my color is: ".$color.". And the farm is: ".$farm;  
  });
  </code></pre>
  
  <p>Inside my "myFunc()", I have the new variable "$farm", which was obtained by the "extract ()" function.</p>
  
  <p>But when I call the function "$functionHelloWorld($fruit,$color);", I'd have to add the new parameter $farm.</p>
  
  <p>But I would like this parameter to fit as needed.</p>
  
  <p>So I thought of making a variable containing a string with the name of each variable to be passed in the parameter (obtained by doing a for () in the array passed as a parameter). Just like this:</p>
  
  <pre><code>$attrList = "";
  $varNames = array_keys($variables);
  for ($i=0; $i &lt; sizeof($varNames); $i++) { 
       $attrList= $attrList."$".$varNames[$i].",";
  }
  $attrList = rtrim($attrList,",");
  </code></pre>
  
  <p>Now, my $attrList has a string like this:</p>
  
  <pre><code>"$fruit,$color,$farm"
  </code></pre>
  
  <p>But I can't just pass ir like a parameter of "$functionHelloWorld" function. Like this:</p>
  
  <pre><code>$functionHelloWorld($attrList);
  </code></pre>
  
  <p>'Cause it'll be interpreted as a string, of course!</p>
  
  <p>And here is where I am stuck!</p>
  
  <p>How can I pass a dynamic amount of attributes passed to a function?</p>
  
  <p>Thanks a lot!</p>