Simple case analysis of PHP Array Operations, array Case Analysis
This example describes PHP Array Operations. We will share this with you for your reference. The details are as follows:
This is a simple PHP array entry question.
$ Str = "as5454654% ^ $ 7675dhasjkdhh12u123123asdasd"; // count the different characters and occurrences of the preceding string.
Implementation Method: Convert the string into an array and obtain the corresponding result through operations on the array.
$ Len = strlen ($ str); // The array contains $ array = array (); for ($ I = 0; $ I <$ len; $ I ++) {array_push ($ array, substr ($ str, $ I, 1 ));}
According to the above conversion function, we get the expected result.
Next, we will use three methods to complete the above.
// Method 1 // sort the array by sort () $ arr = sort ($ array); // remove the duplicate value $ arr1 = array_unique ($ array ); // print the array $ arr1 and you will find that you are continuing to do things. Note the direct relationship between key values
Let's take a look at Method 2:
// Method 2 $ arr2 = array_count_values ($ array); // print the array $ arr2. All problems are solved.
I don't think method 2 is very boring ~
Note:It is best to use PHP automatic functions for any reason.
Method 3:
I will only talk about the idea here: use ACM to sort the element arrays quickly and then process the arrays in blocks.
Let's take a look at this function and give you the above prompt:
Array array_splice (array $ input, int $ offset [, int $ length <[, array $ replacement]) // removes the units specified by offset and length in the input array, if the replacement parameter is provided, // replace it with cells in the replacement array. Returns an array containing the removed cells. Note that the number key name in input is not retained.
There are many ways to solve the problem. Now I want to think about these three types of problems, a simple problem. The less the code is. This is progress.