如何在sql中插入关联数组?

时间:2011-07-19 14:29:02

标签: php sql arrays associative-array

这是我的阵列:

[abominado] => Array
    (
        [0] => réprobo
        [1] => réprobo
        [2] => abominado
        [3] => banido
        [4] => condenado
        [5] => detestado
        [6] => odiado
        [7] => precito
        [8] => renegado
        [9] => repudiado
    )

[abominar] => Array
    (
        [0] => repelir
        [1] => repelir
        [2] => abominar
        [3] => afastar
        [4] => afugentar
        [5] => arredar
        [6] => desalojar
        [7] => desviar
        [8] => detestar
        [9] => empuxar
        [10] => escorraçar
        [11] => espinafrar
        [12] => execrar
        [13] => exercer
        [14] => expulsar
        [15] => grimpar
        [16] => impugnar
        [17] => odiar
        [18] => rebater
        [19] => rechaçar
        [20] => recusar
        [21] => rejeitar
        [22] => relegar
        [23] => repudiar
    )

如何将其插入sql?

3 个答案:

答案 0 :(得分:1)

foreach ($abominado as $key=>$str)
{
    $string .= "$key:$str\n";
}

mysql_query("INSERT INTO strings VALUES ('".mysql_real_escape_string($string)."')");

答案 1 :(得分:0)

您可以使用serialize将其投射到字符串,unserialize获取

答案 2 :(得分:0)

首先,这些数组恰好是顺序的。

其次,在SQL表中,任何列都可以用作搜索条件,因此只需直接插入数据并在任何可搜索列上设置索引。