floridaflatlander Posted May 21, 2014 Share Posted May 21, 2014 I have a single dimensional array of item characteristics called $item[ ], I get the above error when I try to define the functon parameters like this function bread_crumb($item['id'], $dbc) However when I change it to this the function works fine $id = $item['id'];function bread_crumb($id, $dbc) Can you use an array to define a function's parameters and if you can how do you do it? Thanks Link to comment https://forums.phpfreaks.com/topic/288656-parse-error-syntax-error-unexpected-expecting-in-function/ Share on other sites More sharing options...
Jacques1 Posted May 21, 2014 Share Posted May 21, 2014 I think you confuse function definitions and function calls. The parameters of a function definition have nothing to do with outside variables. They are generic placeholders which get concrete values when you call the function: <?php /* * This is a function definition; the parameter $name is a placeholder of the function. * It does not refer to any outside variable, even if there happens to be a variable * called $name as well. */ function hello($name) { echo 'Hello, ' . $name . '.'; } /* * This is a function call. This is when you pass concrete values to the parameters * and execute the function body. */ $you = 'floridaflatlander'; hello($you); Link to comment https://forums.phpfreaks.com/topic/288656-parse-error-syntax-error-unexpected-expecting-in-function/#findComment-1480319 Share on other sites More sharing options...
floridaflatlander Posted May 21, 2014 Author Share Posted May 21, 2014 Your right, I changed the definition to bread_crumb($id, $dbc) and called bread_crumb($item['id'], $dbc) and it worked. Thanks Link to comment https://forums.phpfreaks.com/topic/288656-parse-error-syntax-error-unexpected-expecting-in-function/#findComment-1480345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.