blueman378 Posted December 7, 2008 Share Posted December 7, 2008 Hi guys, Well basically i have a form. a coder can edit this form say ut has username, password, email, location by default, the user can come in and add some more fields, now my script validates this form. but the question i was wondering, i dont know the amount of fields the coder will add, so im thinking for my function how would you go about passing an array to it? is it jsut a case of setting a variable to contain the array eg $form = $fields[fieldname][value] and then to send it to the function: my_function($form) would that work? Link to comment https://forums.phpfreaks.com/topic/135886-function-with-unknown-amount-af-parameters/ Share on other sites More sharing options...
blueman378 Posted December 7, 2008 Author Share Posted December 7, 2008 never mind, 5 seconds thinking and i had the answer <?php function show_values($array) { foreach ($array as $key => $value) { echo $key." - ".$value.""; } } show_values($_POST); ?> Link to comment https://forums.phpfreaks.com/topic/135886-function-with-unknown-amount-af-parameters/#findComment-708385 Share on other sites More sharing options...
blueman378 Posted December 7, 2008 Author Share Posted December 7, 2008 well here's half the answer, but now i need a way to add in an extra value to $_POST because instead of having just name=>value i need name=>type=>value any ideas? <?php function show_values($array) { foreach ($array as $key => $value) { echo $key." - ".$value.""; } } show_values($_POST); ?> (wouldnt let me edit my post) Link to comment https://forums.phpfreaks.com/topic/135886-function-with-unknown-amount-af-parameters/#findComment-708387 Share on other sites More sharing options...
kenrbnsn Posted December 7, 2008 Share Posted December 7, 2008 Just check to see if the value is an array and recursively call your function. If you just want to see what's in $_POST use the print_r function: <?php function show_values($array) { foreach ($array as $key => $value) { if (is_array($value)) show_values($value); echo $key." - ".$value."<br>\n"; } } show_values($_POST); ?> or <?php echo '<pre>' . print_r($_POST,true) . '</pre>' ?> Ken Link to comment https://forums.phpfreaks.com/topic/135886-function-with-unknown-amount-af-parameters/#findComment-708536 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 If you want the type, take a look at var_dump I take it this is for debugging reasons? Link to comment https://forums.phpfreaks.com/topic/135886-function-with-unknown-amount-af-parameters/#findComment-708540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.