By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Invalid Argument

P: n/a
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<strlen($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("original"));

Do you see anything wrong?

Thanks,
Bryan
Oct 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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<strlen($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("original"));

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.
js*******@attglobal.net
==================

Oct 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.