如何将数组转换为MySQL表?

时间:2010-09-24 14:02:55

标签: php mysql row

我想做的是:

$array_data = array( "a" => array(1, 2, 3), "b" => array( 1, 2, 3 ) );

$table_converted = CONVERT_TO_MYSQL_TABLE( $array_data );

while ($row = mysql_fetch_assoc( $table_converted )) {
       echo $row['a'] . " union " . $row['b'];
}

1 个答案:

答案 0 :(得分:0)

循环遍历数组,并使用相同的键构造一个数组,但顺序不同:

$array_data = array( "a" => array(1, 2, 3), "b" => array( 1, 2, 3 ) );

$results = array();
foreach ($array_data as $name => $values)
{
    foreach ($values as $i => $value)
    {
        $results[$i][$name] = $value;
    }
}
print_r($results);