Home >Backend Development >PHP Tutorial >PHP WeChat Public Development Notes (9)_PHP Tutorial

PHP WeChat Public Development Notes (9)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:011007browse

PHP WeChat Public Development Notes (9)

PHP WeChat public development notes series
Date: 2014.9.9

During the Mid-Autumn Festival holiday, I didn’t do much except for Saturday. I went to work today mainly to complete the two established development goals: the two modules of "Bagua" and "Memory". These two things are also very simple and mainly involve database operations. Then just reply in the form of pictures and texts. Therefore, the database mainly stores three field information: article title, article jump link, and picture link.

2014.9.11 Organizing notes:
When I wrote this note, I was working on a feature, so I simply jotted down a few notes about my work at that time. Now that the feature is almost developed, I’m going to sort out the previous notes. At that time, I simply recorded the above sentences.

I am very free this week. It should be said that I have been very free since last week. Otherwise, I would not have time to develop this public platform, so I will seize the time and finish all the functions I want to do before going home. , I will sort it out when I have time later.

Making these two modules is very simple, just create two new data tables in the cloud database. Then just use random numbers to reply. Speaking of random numbers, here I use random numbers with seeds, which can ensure that the random numbers are more random:



The time at the time of call is used as the random number seed, which can ensure the randomness of the random number to the greatest extent.

1. Gossip

When replying to gossip information, I first get all the data rows of gossip information from the database and save them in a two-dimensional array. Then I call the random number above to get a random array subscript, and then get the row's data information. In this way, random replies are achieved:



The classmate said that he hopes to have a sequential reply mechanism, that is, he can reply in the order in the database each time. I have made improvements on this basis, that is, randomly choosing whether to reply in sequence or randomly. This is how I implement sequential replies:



I haven't tested the effect of the sequence, so I don't know if it is useful.
After getting the data information, I responded in the form of pictures and texts. This has been mentioned before and will not be mentioned here again.

2. Memories
This is also achieved by building a data table in the cloud data. But I think that if you recall, you can also recall the gossip information. So I merged the two data tables and used them. The idea of ​​use is: get the gossip from the database, recall the two-dimensional arrays of the two data tables, and then combine the two two-dimensional arrays for use. The rest is almost the same as the gossip.
Let’s talk about merging arrays in php. According to the manual, there are two ways to merge: array_merge(), array_combine(). There is also an introduction to the difference between these two functions on the Internet:
array_combine can only be used to merge two arrays, where the value of one array serves as the key of the new array? The value of the second array as the value of the new array?
array_merge can be used to merge multiple arrays. If there are two key names with the same key name, the key value of the key is the value corresponding to the last key name (the later value overwrites the previous value). If the array is numerically indexed, the key names are re-indexed in a contiguous manner.
So after reading these two introductions, I think it is necessary to merge the two arrays using array_merge, and then do whatever you want.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/879186.htmlTechArticlePHP WeChat Public Development Notes (9) PHP WeChat Public Development Notes Series Date: 2014.9.9 Mid-Autumn Festival except Saturday I adjusted it that day and didn't move much. Going to work today is mainly about taking the established...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn