This article is an example of how PHP array manipulation techniques are concerned. Share to everyone for your reference, as follows:
This is a simple PHP array entry question.
$STR = "AS5454654%^$%^$7675DHASJKDHH12U123123ASDASD";//will be above the statistics above the string different characters and occurrences of the number.
Implementation: Converts a string into an array, resulting in a corresponding result by an array of operations.
$len = strlen ($STR);//array exists in array $array = Array (); for ($i =0; $i < $len; $i + +) { Array_push ($array, substr ($str, $i, 1));}
Based on the conversion function above, we get the result we want.
The next three ways to complete the above.
The sort () method 1//an array $arr = sort ($array);//Remove duplicate values $arr1 = Array_unique ($array);//print Arrays $ARR1 you will find that you continue to do what is needed. Note the direct relationship of the key value
Here's a look at method two:
The most coquettish way two $arr2 = Array_count_values ($array);//print array $arr2 All the problems are solved.
is not think method two very pit Father Ah ~
Note: All can use the PHP automatic function, the best is to use, the reason I do not say, you should also understand
Method Three:
I'm only talking about thinking here: Using the ACM idea, the element array is quickly ranked, and then the arrays are divided into blocks.
Look at this function to give you the above hint:
Array Array_splice (array $input, int $offset [, int $length < [, array $replacement]])//Convert input array by offset and lengt h The specified unit is removed, if the replacement parameter is provided,//is replaced with a cell in the replacement array. Returns an array containing the cells that have been removed. Note the numeric key names in input are not retained.
There are a lot of ways to solve the problem, I now think of these three kinds, a simple question, think more. The code is going to knock less and more. This is progress.
I hope this article is helpful to you in PHP programming.