Position of all characters in the string in php binary n

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.