I need to be able to check whether all elements of an array are valid before doing the queries, if I do it like this:
$arr = array(5, 3, 'test', 23, 9);
$query = $members->prepare("insert into mytable(a) values(:a)");
foreach ($arr as $val) {
if (is_int($val)) {
$query->execute(array(':a'=>$val));
}
}
I only want to insert the values in the array into the database if all of them are ints
, but it inserts the first two values before it gets to 'test' in the array. This is just a random example I made up for the problem that I'm having.
What would be the best way to do this?