3raser Posted June 19, 2010 Share Posted June 19, 2010 I'm learning more stuff, and I don't understand why this isn't working. It's not returning any results. test_index.php <?php include ("test_functions.php"); $array = array("Welcome", "Welcome back", "Good-bye"); echo ParseTest($array, $output); ?> test_functions.php <?php function ParseTest($array) { $output = array_rand($array,1); echo "The random result returned: ". $array[$output['0']] .""; } ?> Link to comment https://forums.phpfreaks.com/topic/205225-very-simple-random-array/ Share on other sites More sharing options...
kenrbnsn Posted June 19, 2010 Share Posted June 19, 2010 You're not returning anything from the function. Replace the "echo" with a "return": <?php function ParseTest($array) { $output = array_rand($array,1); return "The random result returned: ". $array[$output]; } ?> Also, your function has only one parameter, so you should call it using one parameter. Ken Link to comment https://forums.phpfreaks.com/topic/205225-very-simple-random-array/#findComment-1074221 Share on other sites More sharing options...
3raser Posted June 19, 2010 Author Share Posted June 19, 2010 Also, your function has only one parameter, so you should call it using one parameter. Ken Code works, thanks! And what do you mean by this? Link to comment https://forums.phpfreaks.com/topic/205225-very-simple-random-array/#findComment-1074228 Share on other sites More sharing options...
3raser Posted June 19, 2010 Author Share Posted June 19, 2010 ?................................ Link to comment https://forums.phpfreaks.com/topic/205225-very-simple-random-array/#findComment-1074244 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2010 Share Posted June 19, 2010 You declare your function as <?php function ParseTest($array) ?> with one parameter, so you should have only one parameter when you call it: <?php $x = ParseTest($ary); ?> Ken Link to comment https://forums.phpfreaks.com/topic/205225-very-simple-random-array/#findComment-1074246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.