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; { ?> Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/ 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 {. Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075333 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. Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075334 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. Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075336 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 Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075352 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 Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075365 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? Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075372 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 Link to comment https://forums.phpfreaks.com/topic/205496-error-parse-error-trying-to-use-functions/#findComment-1075380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.