Invalid Argument

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BryanA

    #1

    Invalid Argument

    Something seems to be wrong with this function and I can't figure out
    why it is failing. The error that it gives is; Invalid argument
    supplied for foreach() .


    function transposition($ words){
    foreach($words as $word){
    for($x=0;$x<str len($word)-1;$x++){
    $results[] = substr($word, 0, $x) . $word[$x+1] . $word[$x] .
    substr($word, $x+2, strlen($word));
    }
    }
    return $results;
    }

    The way I call the function is:

    echo(correct("o riginal"));

    Do you see anything wrong?

    Thanks,
    Bryan
  • Jerry Stuckle

    #2
    Re: Invalid Argument

    BryanA wrote:
    Something seems to be wrong with this function and I can't figure out
    why it is failing. The error that it gives is; Invalid argument
    supplied for foreach() .
    >
    >
    function transposition($ words){
    foreach($words as $word){
    for($x=0;$x<str len($word)-1;$x++){
    $results[] = substr($word, 0, $x) . $word[$x+1] . $word[$x] .
    substr($word, $x+2, strlen($word));
    }
    }
    return $results;
    }
    >
    The way I call the function is:
    >
    echo(correct("o riginal"));
    >
    Do you see anything wrong?
    >
    Thanks,
    Bryan
    >
    That's because $words is not an array.

    And your echo statement is calling the function 'correct', not the
    function 'transposition' .

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

    Comment

    Working...