在PHP中访问关联数组的内部数组

问题描述 投票:-1回答:1

我从MySQL数据库创建了一个非常简单的ID关联数组。

数组的内容看起来像这样:

[0]=> array(1) { ["id"]=> int(2) } 
[1]=> array(1) { ["id"]=> int(3) } 
[2]=> array(1) { ["id"]=> int(4) } 
[3]=> array(1) { ["id"]=> int(15) } 
[4]=> array(1) { ["id"]=> int(17) } 
[5]=> array(1) { ["id"]=> int(18) } 
[6]=> array(1) { ["id"]=> int(3) } etc.

但是,出于我使用数组的目的,我需要访问ID整数,以便可以将其用于标记父表中的行。但是,我创建的脚本似乎未使用[“ id”] => int(2),因此代码失败。

我具有的代码如下:

MySQL代码:

  public function unused()
    {
        $query = "select person.id from person, thing, person_thing
WHERE flag = 1 AND person.id = person_thing.person_id AND person_thing.thing_id = thing.id and thing.name != 'used'
AND person.name NOT IN (select person.name from person, thing, person_thing WHERE person.id = person_thing.person_id
AND person_thing.thing_id = thing.id and thing.name = 'used')";
        $stmt = $this->Conn->prepare($query);
        $stmt->execute(array());
        return 
        $stmt->fetchAll(PDO::FETCH_ASSOC);

功能代码:

{
        $things = $thing->unused();
        $smarty->assign('thing_used', $things);
        for ($i = 0; $i <= count($things); $i++) {
            $gameView->iterateThings($things[$i]);
        }

迭代方法代码

Public function iterateThings($id)
    {
        $changeFlag = "UPDATE thingview SET flag = false WHERE  id= :id";
        $stmt = $this->Conn->prepare($changeFlag);
        $stmt->execute(array(':id' => $id));

    }

我有一个名为setup的视图,该视图的布尔标志都设置为true。我正在尝试使用此代码更改关联数组$ things中所有person.ids的标志设置。天真的,我以为就足够了,但是每次我运行代码时,标志都保持不变。似乎该数组的内容是:array(1){[“” id“] => int(2)}其中我需要的是{[”“ id”] => int(2) }。我需要索引,而只是数组。我已经无限次用Google搜索了此广告,但未成功。有什么想法吗?

php mysql smarty associative-array
1个回答
0
投票

我意识到我已经创建了一个多维数组。我相信在这一点上,需要对多维数组进行更多的研究,如果需要进一步的帮助,我将重述这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.