How would i write a function to accept X number of parameters
for ex if i want to write a function to insert into a db. i dont know how many fields i will be inserting into the table?
How would i write a function to accept X number of parameters
for ex if i want to write a function to insert into a db. i dont know how many fields i will be inserting into the table?
just use an array to do this.
example.
$data = array ('name'=>'john doe', 'department' => 'sales', 'age'=> 39);
insert_record($data);
function insert_record($data)
{
$sql = 'insert into companytable ';
foreach($data as $field=>$value)
{
//build sql here
$sql .= do stuff here
}
//execute sql command
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.