【问题标题】:Pushing values from one array to another将值从一个数组推送到另一个数组
【发布时间】:2014-02-04 19:50:38
【问题描述】:

任何人都知道如何从中获得:

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 )

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

我正在使用的代码:

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

【问题讨论】:

    标签: php arrays function pdo associative-array


    【解决方案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);
    

    【讨论】:

    • 这正是我想要的!非常感谢!
    猜你喜欢
    • 2021-06-20
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2017-03-02
    • 2015-02-16
    • 2022-12-07
    相关资源
    最近更新 更多