dongqian1893 2012-04-03 19:26
浏览 45
已采纳

PHP中的数组似乎丢弃了元素

I am building an app with complex data which I use arrays for. Some of the data comes direct from fetchs from a postgresql data base and some comes from calculation and processing.

I initally build the array that holds all this and everything goes along fine.

Later during processing I have the following code. This is one section of my code.

    foreach ($this -> detailTables as $key => $detTable) {
        foreach ($detTable['columns'] as $key2 => $column) {
            if ($column['isID'] == 't') {
                $detTable['mainid'] = $column['columnName'];
            }
            if ($column['lookupTable'] != '') {
                $select = array('table' => $column['lookupTable'], 'id' => $column['lookupID'], 'disp' => $column['lookupDisplay']);
                $detTable['lookups'][] = $select;
            }
        }
        logw($key . ' mainid 1', $detTable['mainid']);
        logw($key.' lookups 1', $detTable['lookups']);
    }

    foreach ($this -> detailTables as $key => $detTable) {
        logw($key . ' mainid 2', $detTable['mainid']);
        logw($key.' lookups 2', $detTable['lookups']);
    }

Basically I am scanning detailTables for and their columns to determine and set values for mindid and the lookups array

In the second foreach segment I am just logging the values to see if the persist.

My Log file reads as follows.

columns mainid 1 = columnID
array columns lookups 1
 array 0
  table = tables
  id = tableID
  disp = tableName

tabs mainid 1 = tabID
array tabs lookups 1
 array 0
  table = tables
  id = tableID
  disp = tableName

and the output from the second part reads

columns mainid 2
columns lookups 2
tabs mainid 2
tabs lookups 2

I cannot figure out why the two log sections are not identical.

  • 写回答

2条回答 默认 最新

  • douliaodan2738 2012-04-03 19:36
    关注

    From my understanding of you structure you need to reset the iteration after the first for each through

        }
        logw($key . ' mainid 1', $detTable['mainid']);
        logw($key.' lookups 1', $detTable['lookups']);
    }
    //reset variables here
    foreach ($this -> detailTables as $key => $detTable) {
        logw($key . ' mainid 2', $detTable['mainid']);
        logw($key.' lookups 2', $detTable['lookups']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码