Jump to content

function with unknown amount af parameters,


blueman378

Recommended Posts

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?

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)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.