I beg the master to save me the PHP variable behind the band [] what does it mean
I'll put the key code on it.
foreach ($logData as $key = = $data) {
$kItem [] = $key;//What is behind the variable []
$dItem [] = $data;
$cshu + +;
if ($cshu = = 8) $dItem [] = "I";
}
$field = Implode (', ', $kItem);
$values = "'". Implode ("', '", $dItem). "'";
$this->db->query ("INSERT into".) Db_prefix. "Blog ($field) VALUES ($values)");
The loop reads the array to the eighth data and modifies the value of the $dItem [], but when the data is written, the i is more than one.
SQL statement execution error: INSERT into Emlog_blog (Title,alias,content,excerpt,author,sortid,date,top,allow_remark,allow_tb,hide, Password) VALUES (' DSA ', ' ', ' das ', ' ', ' the ', '-'-1 ', ' 1380936471 ', ' n ', ' I ', ' y ', ' y ', ' n ', ')
Column count doesn ' t match value count at row 1
The reason for the error is because I have an extra I value I want to replace the N in front of I but I don't know why he just can't replace the value PHP
Share to:
------Solution--------------------
$kItem [] = $key;//What is behind the variable []
$kItem this time it's already a number. This means that the current key of the original array is saved as a value in the new array KItem
Adds a new unit to the array.
------Solution--------------------
$kItem [] = $key indicates that the $key is appended to the array $kItem
Equivalent to Array_pish ($kItem, $key)
you if ($cshu = = 8) $dItem [] = "I"; , it is clear that $cshu will have at least one more element than $kItem
Should write
foreach ($logData as $key = = $data) {
$kItem [] = $key;//What is behind the variable []
$dItem [] = $cshu = = 7? "I": $data;
$cshu + +;
}
------Solution--------------------
Reference:
$kItem [] = $key indicates that the $key is appended to the array $kItem
Equivalent to Array_pish ($kItem, $key)
you if ($cshu = = 8) $dItem [] = "I"; , it is clear that $cshu will have at least one more element than $kItem
Should write
foreach ($logData as $key = = $data) {
$kItem [] = $key;//What is behind the variable []
$dItem [] = $cshu = = 7? "I": $data;
$cshu + +;
}
Hit the wrong bird. Array_push
------Solution--------------------
This is a typical example of adding data to a database in the form of an array. You can refer to this article
It's easy to understand. http://blog.csdn.net/timecolor/article/details/8982615