PHP micro-Credit Public Development Notes series
Date: 2014.9.9
The Mid-Autumn festival holiday except Saturday Day the whole, not how to move. Today to work mainly to the established two development goals completed: "Gossip", "recall" two modules, these two things are also very simple, but also mainly related to the operation of the database. Then you can reply in the form of a text. So the main database is saved: article title, article jump connection, Picture link these three fields of information.
2014.9.11 to organize notes:
Write this note, in the rush function, so that is simply a few strokes of the work of the time, now the function developed almost, just to tidy up the previous notes. It was very simple to record the above sentences.
This week is very idle, it should be said that last week I have been very idle, otherwise there will not be time to toss the development of the public platform, so seize the time before going home to do the function to do it, there is time to finish it.
To do these two modules, is very simple, that is, in the cloud database to create a new two data tables on it. And then just use random numbers to reply to it. When it comes to random numbers, here I use random numbers with seeds to keep random numbers more random:
The time of the call is a random number of seeds, so as to guarantee the randomness of random numbers to a maximum extent.
First, gossip
When replying to the gossip information, I first get all the gossip data rows from the database, save in a two-dimensional array, then call the random number above to get a random array subscript, then get the data information of this line. This allows for a random response:
Classmate said that want to have the mechanism of sequential response, that is, each time you can follow the order in the database to reply, I have made improvements on this basis, that is, the random choice is the sequential response or random response. Sequential reply I did so:
The order did not detect the effect, do not know if there is no use.
After getting the data information, it is to reply in the form of a text, which has been mentioned before and is not mentioned here.
Second, memories
This is also the data in the cloud to build a data table to achieve. But I think, recall words, also can recall the gossip information. So I combined the two data tables. The use of the idea is: from the database to get gossip, memories of two of the two-dimensional array of data tables, and then the two two-dimensional arrays together to use, the rest is the same as the gossip piece.
Here's a talk about merging arrays in PHP. The manual says there are two ways to merge: Array_merge (), Array_combine (). There is also a difference between these two functions on the Web:
Array_combine can only be used for merging two arrays, where the value of one array is the key of the new array? The value of the second array as the value of the new array?
Array_merge can be used for merging multiple arrays, and if two key names are the same, the key value is the value of the last key name (the following value overrides the previous value). If the array is a numeric index, the key name is indexed in a sequential manner.
So after reading these two introductions, I think it's necessary to merge the two arrays in a array_merge way, and then what to do.