Hello all,
I'm trying to create an "expected field" array from the fields of the database. So for instance when a form is submitted only valid fields are allowed.
I'm using a nested loop to do this but there is some weirdness that I'm sure has a simple explanation but can't find out what it is so I thought I'd ask. The expected array is including some unexpected results - something like [0] => site_id [1] => 0 [2] => site_name [3] => 1
[0] => page_id and [2] => page_name are desired however [1] => 0 and [3] => 1 are undesirables and not in the database. If I put
if (is_numeric($key)) continue;
it gets rid of them but I'm guessing there is a better way to try and do what I want to do.
$expected = array();//initialize expected array
$get_table_array = array('page','content');//tables to query for the columns to include in the expected array
foreach($get_table_array as $table){
$result = get_all_table_columns($table);//function that returns results of a PDO query of each table
foreach($result as $row){
foreach($row as $key=>$value){
if (is_numeric($key)) continue;//If I include this bit of code it gets rid of the extras but I feel it's over kill and must be a better way?
$expected[] = $key;//create the expected field array
}//foreach($row as $key=>$value){
}//foreach ($result as $row) {
}//foreach($get_table_array as $value){
So to recap the desired expected array is 'page_id', 'page_name' etc not 'page_id', '0', 'page_name', '1' etc.
Thanks so much in advance, I'm hope it's something simple I'm missing.
-Twitch