如何获取fetchAll的数字项?

时间:2017-07-12 05:29:14

标签: php pdo

以下是我的代码的结果:

$res = $stm->fetchAll();
/*
Array
(
    [0] => Array
        (
            [name] => apple
            [0] => apple
            [colour] => red
            [1] => red
        )

    [1] => Array
        (
            [name] => pear
            [0] => pear
            [colour] => green
            [1] => green
        )
)

如果我使用fetchAll(PDO::FETCH_ASSOC),结果将是:

/*
Array
(
    [0] => Array
        (
            [name] => apple
            [colour] => red
        )

    [1] => Array
        (
            [name] => pear
            [colour] => green
        )
)

现在我想知道,我怎么能得到这个?

/*
Array
(
    [0] => Array
        (
            [0] => apple
            [1] => red
        )

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

注意PDO::FETCH_COLUMN不会返回预期结果。

1 个答案:

答案 0 :(得分:3)

使用PDO::FETCH_NUM

a = Food, Drinks, Shopping...

试试这个