while()循环数组merge()以数组形式$ row ['field_name']访问while()之外的那些值

时间:2012-01-05 23:12:55

标签: php arrays while-loop

这解析我的查询。 $ merge var包含我需要的确切结构。

我想要做的是获取$ merge数据并将其作为数组处理并获取$ row [0],$ row [1],$ row [3]等中的每个值... while循环。

while ($row = mysql_fetch_row($query)) {
    $industries = explode(",", $row[13]);
    unset($row[13]);
    $merge = array_merge($row, $industries);
}

$ merge输出示例:

Array
(
   [0] => 3122
   [1] => Painting Services
   [2] => 
   [3] => 1234567 Tew Street
   [4] => 
   [5] => Andover
   [6] => MA
   [7] => 
   [8] => 01801
   [9] => 000-555-1212
   [10] => 000-555-1212
   [11] => 
   [12] => www.not-a-real-site.ooo
   [13] => Roofing 
)

Array
(
   [0] => 3123
   [1] => Hobow Corporation
   [2] => 
   [3] => 115 Sound Plaza, 117th Floor
   [4] => 
   [5] => Woodbridge
   [6] => NJ
   [7] => 
   [8] => 07111
   [9] => 000-555-1212
   [10] => 000-555-1212
   [11] => 
   [12] => www.not-a-real-site.ooo
   [13] => Energy
)

1 个答案:

答案 0 :(得分:0)

$rows = array();
while ($row = mysql_fetch_row($query)) {
    $industries = explode(",", $row[13]);
    unset($row[13]);
    $rows[] = array_merge($row, $industries);
}