将值从一个数组推送到另一个数组

时间:2014-01-16 03:19:44

标签: php arrays function pdo associative-array

任何人都知道如何摆脱这个:

Array ( [0] => 0 ) 
Array ( [0] => 1 ) 
Array ( [0] => 1 ) 
Array ( [0] => 1 ) 
Array ( [0] => 0 ) 

到此:

Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 0 )

我无法找到答案;任何片段或示例将不胜感激。 请不要评论代码中的漏洞;我知道它已经存在了。我只是一个初学者......我只是希望它的核心内容能够发挥作用。

我正在使用的代码:

    // 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();
        }
}

1 个答案:

答案 0 :(得分:1)

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);