Ask the master to save my little brother. What do you mean by the back of the PHP variable?

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.