I query a series of tables in order to print these, and I want to print all keys of each table even if the values are empty, but a specific set of keys which are the same for each table shall not be printed.
My query and fetch of the result in an array for one table:
$stmt = $db_conn->prepare("SELECT * FROM table;");
$stmt->execute();
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
var_export($array);
returns:
array ( 0 => array ( 'a' => '1', 'b' => '2018-12-21', 'c' => '', 'd' => '', ), )
I prepared a list of bad keys in an array:
var_export($bad_keys);
returns:
array ( 0 => array ( 'a' => '1', 'b' => '2019-01-05', ), )
For each table I want to exclude the bad keys {a, b} from the query result in $array
by use of array_diff_key()
:
$array_new = array_diff_key($array, $bad_keys);
var_dump($array_new);
returns empty:
array(0) { }
.
$array_new
should have the keys {'c', 'd'} but it has not. I don't see a mistake in my code. Please help.