Hi,
I have an array made up of variables, and I want to apply a function to each item of the array, to make each item a quoted string, which will then be passed to another function to construct a sql statement to insert the values into the database.
So, I have:
$dbarray = array($name, $id, $add);
$newarray = array_walk($dbarray, 'myfunction');
$sql = "INSERT INTO $table VALUES($newarray);
OR,
$sql = "INSERT INTO $table VALUES(".join(",",array_walk($dbarray, 'myfunction')).");
function myfunction($value)
{
return("\"".$value."\"");
}
I've tried a few things here. I've tried getting rid of newarray and just putting the array_walk call inside the sql statement, I've tried setting newarray to array(array_walk...), and none of this is producing any kind of workable result.
Can someone give me a little more insight into what array_walk is doing under the hood? The details in the docs are somewhat lacking, or at least don't really tell me what I need to know for my particular situation.