What does it mean to save my PHP variable []?

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

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.