3raser Posted June 22, 2010 Share Posted June 22, 2010 My first or second time learning/using functions. My error: Parse error: parse error in C:\wamp\www\learning\functions.php on line 9 Index.php <?php include("functions.php"); $array = array("dog","cat","wolf"); echo ImplodeTest($array, $space_them); ?> Functions.php <?php function ImplodeTest($array, $space_them) { $space_them = implode('-', $array); return $space_them; { ?> Quote Link to comment Share on other sites More sharing options...
Alex Posted June 22, 2010 Share Posted June 22, 2010 You're trying to close your function with the wrong curly bracket. Should be } not {. Quote Link to comment Share on other sites More sharing options...
3raser Posted June 22, 2010 Author Share Posted June 22, 2010 You're trying to close your function with the wrong curly bracket. Should be } not {. Rofl....... Thank you. Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 22, 2010 Share Posted June 22, 2010 Your blocks need to match { .... } Notice how you used { .... and then { again. Quote Link to comment Share on other sites More sharing options...
3raser Posted June 22, 2010 Author Share Posted June 22, 2010 Now I'm starting to get the hang of it, but I just introduced arrays to functions and it's a bit confusing. <?php include("functions.php"); $name[0] = "Justin"; $name[1] = "John"; $name[2] = "Tanner"; echo Test($name); ?> <?php function Test($name) { if($name[0]=="Justin") { echo "Success."; } else { echo "Failure."; } return $name; } ?> Why is that giving me the result: Failure.Justin Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 22, 2010 Share Posted June 22, 2010 You have one echo in the function and one echo of what the function is returning. You probably want something like this: <?php function Test($name) { if($name[0]=="Justin") { return "Success."; } else { return "Failure."; } } ?> Ken Quote Link to comment Share on other sites More sharing options...
3raser Posted June 22, 2010 Author Share Posted June 22, 2010 Thank you! But why does it still say Failure? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 22, 2010 Share Posted June 22, 2010 Are you sure you're testing with the correct files? When I test the code on my server, it works fine. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.