felito Posted June 2, 2011 Share Posted June 2, 2011 hi function livre($form_data_array['ensino']) { } this code give me a syntax error, why? what is the correct way? thanks Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/ Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 Hi. Syntax error give you reason for code not working. Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224075 Share on other sites More sharing options...
felito Posted June 2, 2011 Author Share Posted June 2, 2011 syntax error, unexpected '[', expecting ')' Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224077 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 Please read: http://php.net/manual/en/functions.arguments.php Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224079 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 I don't understand the point of you using an array as a function variable either. Post the rest of your code. Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224080 Share on other sites More sharing options...
felito Posted June 2, 2011 Author Share Posted June 2, 2011 obviously that know that i can do $var1 = $form_data_array["ensino"]; function livre($var1) { } i serialize an array and now i need to get the values, basically i want to reduce some lines of code, because i have much variables from serialize. so, the correct syntax is: function livre($form_data_array) { $form_data_array["ensino"]; } correct? Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224085 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 Once again, you need to post the rest of your code. Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224088 Share on other sites More sharing options...
Pikachu2000 Posted June 2, 2011 Share Posted June 2, 2011 Are you trying to define the function, or call it? If you're defining it, just use a standard variable name for the argument. Use the array element when you call the function. $array = range( 1, 25 ); function check_array($input) { if( is_array($input) ) { return "Array"; } else { return "Not array"; } } echo check_array( $array ); echo '<br>'; echo check_array( $array[5] ); Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224097 Share on other sites More sharing options...
felito Posted June 2, 2011 Author Share Posted June 2, 2011 $form_data_array = array(); $form_data_array = $_POST['myformdata']; echo $form_data_array["age"]; //display age correctly function check($form_data_array) { if (empty($form_data_array["age"])){ echo ("empty"); } else echo ("not empty"); } I need to check if the $form_data_array["age"]; is empty or no Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224102 Share on other sites More sharing options...
teynon Posted June 2, 2011 Share Posted June 2, 2011 This code is different than what you originally posted. However, you should put the function above that code and then you need to actually call the function. IE check($varable); Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224106 Share on other sites More sharing options...
felito Posted June 2, 2011 Author Share Posted June 2, 2011 oh god. sorry, shame solved Quote Link to comment https://forums.phpfreaks.com/topic/238204-array-in-function/#findComment-1224108 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.