我面临一个小问题,我不知道是否有可能实现它。让我解释一下:
我有一个像这样的关联数组:
Array
(
[res_id] => 104
[subject] => Test
[type_id] => 503
[format] => pdf
[typist] => fefe
[creation_date] => 2017-02-10 14:27:37.236711
[modification_date] => 2017-02-10 14:27:37.236711
[fulltext_result] => 1
[doc_date] => 2017-02-01 00:00:00
[docserver_id] => FASTHD_MAN
[path] => 2017#02#0001##
[filename] => 0008.pdf
[fingerprint] =>
[filesize] => 84979
[status] => VAL
[destination] => DSG
[priority] => 2
[is_multi_docservers] => N
[is_frozen] => N
[tablename] => res_letterbox
[initiator] => COU
[dest_user] => ddaull
[locker_user_id] => fefefef
[locker_time] => 2017-02-13 15:52:25.624521
[confidentiality] => N
[tnl_path] => 2017#02#0001##
[tnl_filename] => 0008.png
)
我想知道我是否可以使用这个关联数组,以便进行INSERT TO请求?我希望数组的第一部分(如res_id,subject)转到列部分进行插入。数组的第二部分(如104,Test)将转到值
先谢谢你的帮助,希望我足够清楚..
答案 0 :(得分:1)
@ Nathan30试试这个:
<?php
$arr = array(
"res_id" => 104,
"subject" => "Test",
"type_id" => 503,
"format" => "pdf",
"typist" => "fefe",
"creation_date" => "2017-02-10 14:27:37.236711",
"modification_date" => "2017-02-10 14:27:37.236711",
"fulltext_result" => 1,
"doc_date" => "2017-02-01 00:00:00",
"docserver_id" => "FASTHD_MAN",
"path" => "2017#02#0001##",
"filename" =>" 0008.pdf",
"fingerprint" => "",
"filesize" => 84979,
"status" => "VAL",
"destination" => "DSG",
"priority" => 2,
"is_multi_docservers" => "N",
"is_frozen" => "N",
"tablename" => "res_letterbox",
"initiator" => "COU",
"dest_user" => "ddaull",
"locker_user_id" => "fefefef",
"locker_time" => "2017-02-13 15:52:25.624521",
"confidentiality" => "N",
"tnl_path" => "2017#02#0001##",
"tnl_filename" => "0008.png",
);
echo "<pre>";
print_r($arr);
$column = array();
$values = array();
foreach($arr as $key => $value){
$column[] = $key;
$values[] = $value;
}
now query will be like:
"insert into table values(".implode(',', $column).") values (".implode(',', $values).")";