trivial arguments function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jhullu@gmail.com

    trivial arguments function

    hi all

    i've a function F as

    function F($arg1,$arg2,$ arg3){
    ....
    }

    and a variable $args = "A,B,C"

    my goal is to call the function with the content of $args.

    if i call f($args) i call this function with 1 argument : an array, i
    wish call function as f(A,B,C)

    If Someone thinks this is possible... please give me the code ;))

    regards.

  • Jerry Stuckle

    #2
    Re: trivial arguments function

    jhullu@gmail.co m wrote:
    hi all
    >
    i've a function F as
    >
    function F($arg1,$arg2,$ arg3){
    ...
    }
    >
    and a variable $args = "A,B,C"
    >
    my goal is to call the function with the content of $args.
    >
    if i call f($args) i call this function with 1 argument : an array, i
    wish call function as f(A,B,C)
    >
    If Someone thinks this is possible... please give me the code ;))
    >
    regards.
    >
    f($args[0]. $args[1], $args[2]);

    Or -
    f($arg1, $arg2=null, $arg3=null) {
    if (is_array($arg1 ) && $arg2==null && $arg3 == null) {
    if (count($arg1) == 3)
    $arg2 = $arg1[1];
    $arg3 = $arg1[2];
    $arg1 = $arg1[0];
    }
    else {
    echo "Insufficie nt number of parameters passed<br>\n";
    exit();
    }
    }
    ... rest of stuff here
    }

    Of course you should do other checking to ensure you're passing 3
    arguments in the array.


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Chung Leong

      #3
      Re: trivial arguments function


      jhullu@gmail.co m wrote:
      hi all
      >
      i've a function F as
      >
      function F($arg1,$arg2,$ arg3){
      ...
      }
      >
      and a variable $args = "A,B,C"
      >
      my goal is to call the function with the content of $args.
      >
      if i call f($args) i call this function with 1 argument : an array, i
      wish call function as f(A,B,C)
      >
      If Someone thinks this is possible... please give me the code ;))
      >
      regards.
      call_user_func_ array('F', explode(',' $args));

      Comment

      Working...