我有一个返回一组数据的MySQL查询。然后,我会执行foreach
循环来检查所有以 Seq 开头的字段,其中包含 1 。
每个字段集都有许多字段以及注释字段。
示例:
Seq1001, Seq1002, seq1003, Seq1004, Comments01
Seq2001, Seq2002, seq2003, Seq2004, Comments02
Seq3001, Seq3002, seq3003, Seq3004, Comments03
如果 Seq2002 包含 1 ,请获取 Comments02
的内容我已经有了循环查询结果的代码,该查询查找包含 1 的任何 Seq 字段,但同时我如何才能获得评论栏。
我的“foreach”循环代码
foreach ($row_RoomAudit as $key => $val) {
if (strpos($val, '1') !== FALSE && substr( $key, 0, 3)=='Seq' ){
print $key;
}
}
Array ( [RecordID] => 133 [UniqueID] => 1191 [HotelID] => Rose [Room] =>1256
[AuditBy] => ANOther [AuditorID] => 474
[LastAudit] => 2013-09-05 10:38:00
[Complete] => 1 [Fail] => 1 [CompleteDate] => 2013-09-05 10:41:00
[CompStamp] => 2013-09-05 [SeqID0101] => 1
[SeqID0101RD] => [SeqID0102] => 1
[SeqID0102RD] => [SeqID0103] => 0
[SeqID0103RD] => [SeqID0104] => 0
[SeqID0104RD] => [SeqID0105] => 0
[SeqID0105RD] => [SeqID0106] => 0 [SeqID0106RD] => [SeqID0107] => 0
[SeqID0107RD] => [SeqID0108] => 0 [SeqID0108RD] => [SeqID0109] => 0
[SeqID0109RD] => [SeqID0110] => 0
[SeqID0110RD] => [Comments01] => [SeqID0201] => 0
[SeqID0201RD] => [SeqID0202] => 0 [SeqID0202RD] => [SeqID0203] => 0
[SeqID0203RD] => [Comments02] => [SeqID0301] => 0 [SeqID0301RD] => [SeqID0302] => 0 [SeqID0302RD] => [SeqID0303] => 0
[SeqID0303RD] => [SeqID0304] => 0
[SeqID0304RD] => [Comments03] => [SeqID0401] => 0
[SeqID0401RD] => [SeqID0402] => 0
[SeqID0402RD] => [SeqID0403] => 0
[SeqID0403RD] => [SeqID0404] => 0
[SeqID0404RD] => [Comments04] => [SeqID0501] => 0
[SeqID0501RD] => [SeqID0502] => 0
[SeqID0502RD] => [Comments05] => [SeqID0601] => 0 [SeqID0601RD] => [SeqID0602] => 0
[SeqID0602RD] => [Comments06] => [SeqID0701] => 0 [SeqID0701RD] => [SeqID0702] => 0
[SeqID0702RD] => [Comments07] => [SeqID0801] => 0
[SeqID0801RD] => [SeqID0802] => 0
[SeqID0802RD] => [Comments08] => [SeqID0901] => 0
[SeqID0901RD] => [SeqID0902] => 0
[SeqID0902RD] => [SeqID0903] => 0
[SeqID0903RD] => [Comments09] => [SeqID1001] => 0
[SeqID1001RD] => [SeqID1002] => 0 [SeqID1002RD] => [SeqID1003] => 0
[SeqID1003RD] => [SeqID1004] => 0
[SeqID1004RD] => [Comments10] => [SeqID1101] => 0 [SeqID1101RD] => [SeqID1102] => 0
[SeqID1102RD] => [SeqID1103] => [Comments11] => [SeqID1201] => 0
[SeqID1201RD] => [Comments12] => [SeqID1301] => 0 [SeqID1301RD] => [SeqID1302] => 0 [SeqID1302RD] => [SeqID1303] => 0
[SeqID1303RD] => [SeqID1304] => 0 [SeqID1304RD] => [SeqID1305] => 0 [SeqID1305RD] => [SeqID1306] => 58.3
[SeqID1306RD] => [SeqID1307] => 21.9 [SeqID1307RD] => [SeqIDH1305] => [SeqIDH1306] => [Comments13] => [SeqID1401] => 0
[SeqID1401RD] => [SeqID1402] => 0 [SeqID1402RD] => [SeqID1403] => 0 [SeqID1403RD] => [SeqID1404] => 0
[SeqID1404RD] => [SeqID1405] => 0 [SeqID1405RD] => [SeqID1406] => 0 [SeqID1406RD] => [SeqID1407] => 0
[SeqID1407RD] => [SeqID1408] => 0 [SeqID1408RD] => [SeqID1409] => 0 [SeqID1409RD] => [SeqID1410] => 0
[SeqID1410RD] => [SeqID1411] => 0
[SeqID1411RD] => [Comments14] => [SeqID1501] => 0 [SeqID1501RD] => [SeqID1502] => 0 [SeqID1502RD] => [SeqID1503] => 0
[SeqID1503RD] => [SeqID1504] => 0
[SeqID1504RD] => [SeqID1505] => 0 [SeqID1505RD] => [Comments15] => [SeqID1601] => 0
[SeqID1601RD] => [SeqID1602] => 0 [SeqID1602RD] => [SeqID1603] => 0 [SeqID1603RD] => [SeqID1604] => 0
[SeqID1604RD] => [SeqID1605] => 0
[SeqID1605RD] => [Comments16] => [SeqID1701] => 0
[SeqID1701RD] => [SeqID1702] => 0 [SeqID1702RD] => [SeqID1703] => 0 [SeqID1703RD] => [SeqID1704] => 0
[SeqID1704RD] => [SeqID1705] => 0 [SeqID1705RD] => [Comments17] => [SeqID1801] => 0
[SeqID1801RD] => [SeqID1802] => 0
[SeqID1802RD] => [Comments18] => [SeqID1901] => 0
[SeqID1901RD] => [SeqID1902] => 0 [SeqID1902RD] => [Comments19] => [SeqID2001] => 0
[SeqID2001RD] => [SeqID2002] => 0 [SeqID2002RD] => [Comments20] => [SeqID2101] => 0
[SeqID2101RD] => [SeqID2102] => 0 [SeqID2102RD] => [Comments21] => [SeqID2201] => 0
[SeqID2201RD] => [SeqID2202] => 0
[SeqID2202RD] => [SeqID2203] => 0 [SeqID2203RD] => [Comments22] => [SeqID2301] => 0 [SeqID2301RD] => [SeqID2302] => 0 [SeqID2302RD] => [Comments23] => [SeqID2401] => 0
[SeqID2401RD] => [SeqID2402] => 0 [SeqID2402RD] => [SeqID2403] => 0 [SeqID2403RD] => [Comments24] => [SeqID2501] => 0
[SeqID2501RD] => [SeqID2502] => 0 [SeqID2502RD] => [SeqID2503] => 0 [SeqID2503RD] => [Comments25] => [SeqID2601] => 0 [SeqID2601RD] => [SeqID2602] => 0 [SeqID2602RD] => [SeqID2603] => 0 [SeqID2603RD] => [Comments26] => [SeqID2701] => 0 [SeqID2701RD] => [SeqID2702] => 0 [SeqID2702RD] => [SeqID2703] => 0 [SeqID2703RD] => [SeqID2704] => 0 [SeqID2704RD] => [SeqID2705] => [SeqID2705RD] => [Comments27] => [SeqID2801] => 0 [SeqID2801RD] => [Comments28] => [SeqID2901] => 0 [SeqID2901RD] => [SeqID2902] => 0 [SeqID2902RD] => [Comments29] => [SeqID3001] => 0 [SeqID3001RD] => [SeqID3002] => 0 [SeqID3002RD] => [Comments30] => [SeqID3101] => 0 [SeqID3101RD] => [Comments31] => [SeqID3201] => 0 [SeqID3201RD] => [SeqID3202] => 0 [SeqID3202RD] => [SeqID3203] => 0 [SeqID3203RD] => [SeqID3204] => 0 [SeqID3204RD] => [Comments32] => [SeqID3301] => 0 [SeqID3301RD] => [SeqID3302] => 0 [SeqID3302RD] => [Comments33] => [SeqID3401] => 0 [SeqID3401RD] => [SeqID3402] => 0 [SeqID3402RD] => [SeqID3403] => 0 [SeqID3403RD] => [Comments34] => [SeqID3501] => 0 [SeqID3501RD] => [SeqID3502] => 0 [SeqID3502RD] => [Comments35] => [SeqID3601] => 0 [SeqID3601RD] => [SeqID3602] => 0 [SeqID3602RD] => [SeqID3603] => 0 [SeqID3603RD] => [SeqID3604] => 0 [SeqID3604RD] => [SeqID3605] => 0 [SeqID3605RD] => [SeqID3606] => 0 [SeqID3606RD] => [Comments36] => [SeqID3701] => 0 [SeqID3701RD] => [SeqID3702] => 0 [SeqID3702RD] => [SeqID3703] => 0 [SeqID3703RD] => [SeqID3704] => 0 [SeqID3704RD] => [Comments37] => [SeqID3801] => 0 [SeqID3801RD] => [SeqID3802] => 0 [SeqID3802RD] => [SeqID3803] => 0 [SeqID3803RD] => [SeqID3804] => 0 [SeqID3804RD] => [Comments38] => [SeqID3901] => 0 [SeqID3901RD] => [SeqID3902] => 0 [SeqID3902RD] => [SeqID3903] => 0 [SeqID3903RD] => [SeqID3904] => 0 [SeqID3904RD] => [Comments39] => [SeqID4001] => 0 [SeqID4001RD] => [SeqID4002] => 0 [SeqID4002RD] => [SeqID4003] => 0 [SeqID4003RD] => [Comments40] => [SeqID4101] => 0 [SeqID4101RD] => [SeqID4102] => 0 [SeqID4102RD] => [Comments41] => [SeqID4201] => 0 [SeqID4201RD] => [SeqID4202] => 0 [SeqID4202RD] => [Comments42] => [SeqID4301] => 0 [SeqID4301RD] => [SeqID4302] => 0 [SeqID4302RD] => [SeqID4303] => 0 [SeqID4303RD] => [SeqID4304] => 0 [SeqID4304RD] => [Comments43] => [SeqID4401] => 0 [SeqID4401RD] => [Comments44] => [SeqID4501] => 0 [SeqID4501RD] => [SeqID4502] => 0 [SeqID4502RD] => [SeqID4503] => 0 [SeqID4503RD] => [SeqID4504] => 0 [SeqID4504RD] => [SeqID4505] => 0 [SeqID4505RD] => [SeqID4506] => 0 [SeqID4506RD] => [SeqID4507] => 0 [SeqID4507RD] => [SeqID4508] => 0 [SeqID4508RD] => [SeqID4509] => 0 [SeqID4509RD] => [SeqID4510] => 0 [SeqID4510RD] => [SeqID4511] => 0 [SeqID4511RD] => [SeqID4512] => 0 [SeqID4512RD] => [SeqID4513] => 0 [SeqID4513RD] => [SeqID4514] => 0 [SeqID4514RD] => [Comments45] => [SeqID4601] => 0 [SeqID4601RD] => [SeqID4602] => 0 [SeqID4602RD] => [SeqID4603] => 0 [SeqID4603RD] => [SeqID4604] => 0 [SeqID4604RD] => [Comments46] => [SeqID4701] => [SeqID4702] => [SeqID4703] => [SeqID4704] => [SeqID4705] => [Comments47] => )
我需要保留$ key的当前值,以便稍后在脚本中使用。