foreach ($idDiscontinuedArray as $id) {
$stmt = $dbh->query("SELECT discontinued FROM `$id` ORDER BY `date` DESC LIMIT 1");
$rows = $stmt->fetch(PDO::FETCH_NUM);
$tempArr[] = $rows[0];
}
print_r($tempArr);
Pushing values from one array to another
-
28-09-2022 - |
Question
Anyone know how to get from this:
Array ( [0] => 0 )
Array ( [0] => 1 )
Array ( [0] => 1 )
Array ( [0] => 1 )
Array ( [0] => 0 )
to this:
Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 0 )
I'm having trouble getting towards the answer; any snippets or examples would be greatly appreciated. Please don't comment about vulnerabilities in the code; I know it's already there. I am just a beginner...I just want the core guts of it to work.
My code that I am using:
// Function that checks if items are already discontinued or not
function checkDiscontinued($dbh, $idDiscontinuedArray) {
try {
foreach ($idDiscontinuedArray as $id) {
$stmt = $dbh->query("SELECT discontinued FROM `$id` ORDER BY `date` DESC LIMIT 1");
$rows = $stmt->fetch(PDO::FETCH_NUM);
print_r($rows);
echo '<br>';
}
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow