What does it mean to save my PHP variable []? php
I will paste the key code
Foreach ($ logData as $ key => $ data) {$ kItem [] = $ key; // What is [] next to the variable $ dItem [] = $ data; $ cshu ++; if ($ cshu = 8) $ dItem [] = "I" ;}$ field = implode (',', $ kItem ); $ values = "'". implode ("','", $ dItem ). "'"; $ this-> db-> query ("insert ". DB_PREFIX. "blog ($ field) VALUES ($ values )");
The value of $ dItem [] is changed to I when the array is read cyclically to the eighth data, but this I is more when writing data.
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 ','', '39', '-1', '000000', 'n', 'I', 'y', 'y ', 'N ','')
Column count doesn't match value count at row 1
The error is reported because there is an extra I value. I want to replace N before I, but I don't know why it cannot be replaced.
Reply to discussion (solution)
$ KItem [] = $ key; // What is [] next to the variable?
$ KItem this time is already an array. the above means to save the current key of the original array as a value to the new array kItem.
Adds new units to the array.
$ KItem [] = $ key; // What is [] next to the variable?
$ KItem this time is already an array. the above means to save the current key of the original array as a value to the new array kItem.
Adds new units to the array.
Thanks, but I want to replace the array variable in the loop for 8th times, but he helped me realize that the original value is 12 and now it turns into 13 because if ($ cshu = 8) $ dItem [] = "I"; the replacement fails to be output.
May I ask $ dItem [] = $ data?
$ DItem [] = $ data; replace the value with I. How do I write code?
$ KItem [] = $ key indicates appending $ key to an array after $ kItem
Equivalent to array_pish ($ kItem, $ key)
If ($ cshu = 8) $ dItem [] = "I"; then, it is clear that $ cshu must have at least one element more than $ kItem
Ying writing
Foreach ($ logData as $ key => $ data) {$ kItem [] = $ key; // What is [] next to the variable here $ dItem [] = $ cshu = 7? "I": $ data; $ cshu ++ ;}
$ KItem [] = $ key indicates appending $ key to an array after $ kItem
Equivalent to array_pish ($ kItem, $ key)
If ($ cshu = 8) $ dItem [] = "I"; then, it is clear that $ cshu must have at least one element more than $ kItem
Ying writing
Foreach ($ logData as $ key => $ data) {$ kItem [] = $ key; // What is [] next to the variable here $ dItem [] = $ cshu = 7? "I": $ data; $ cshu ++ ;}
Hit the wrong bird .. Array_push
This is a typical example of adding data to the database in the form of arrays. Refer to this article
It is easy to understand. Http://blog.csdn.net/timecolor/article/details/8982615