: This article mainly introduces the position of all characters in the string in the php binary n. For more information about PHP tutorials, see. Zookeeper
Today, when I wrote a function, I used some small and fragmented knowledge points to summarize them in the form of simple examples.
$ Array = array );
$ Ac = array_count_values ($ array); // Number of times all characters in the array appear
Print_r ($ ac );
Echo pow (); // calculate the power 1 of 2
Echo "\ n ";
Echo decbin (1); // converts decimal 1 to binary
Echo "\ n ";
$ L = 4;
$ O = 0;
Echo $ k = sprintf ("% 0 {$ l} d", $ o); // set the length of the string, which is less than the previous zero
Echo "\ n ";
Function getCharpos2 ($ str, $ char) {// This is a function found online. it obtains all the positions of a character in the string and forms an array.
$ J = 0;
$ Arr = array ();
$ Count = substr_count ($ str, $ char );
For ($ I = 0; $ I <$ count; $ I ++ ){
$ J = strpos ($ str, $ char, $ j );
$ Arr [] = $ j;
$ J = $ j + 1;
}
Return $ arr;
}
$ C = getCharpos2 ("10011", '1 ');
Print_r ($ c );
Echo "\ n ";
$ S = 'abcdefg ';
Var_dump (str_split ($ s, 1); separates one character from each other to form an array
$ Array = array ('0', '0', '1 ');
Echo implode ($ array); // combines the array into a string
?>
Output contacts are as follows:
Array
(
[4] => 1
[5] => 1
[1] => 3
[2] => 2
[3] => 1
)
2
1
0000
Array
(
[0] => 0
[1] => 3
[2] => 4
)
Array (7 ){
[0] =>
String (1) ""
[1] =>
String (1) "B"
[2] =>
String (1) "c"
[3] =>
String (1) "d"
[4] =>
String (1) "e"
[5] =>
String (1) "f"
[6] =>
String (1) "g"
}
001
The preceding section describes the position of all characters in the string of the php binary n, including the following content. it is helpful to anyone interested in the PHP Tutorial.