Home > Article > Backend Development > How to query the position of the first element in php
How to query the position of the first element in php: 1. Create a new php file; 2. Enter the code "$str = 'abcdef';"; 3. Use the strpos() function to find the character "a "The location where it first appears is sufficient.
#The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to query the position of the first element in php?
Find the position where the string first appears:
Create a new index.php file, as shown in the figure:
Declare the file type and encoding for PHP to interact with the browser, as shown in the figure:
Input code: $str = 'abcdef';
Use the strpos() function to find the position where the character 'a' first appears, as shown in the figure:
Use the var_dump() function to output the return value $pos, as shown in the picture:
Run the web page, you can see that the index value of character 'a' is 0, as shown in the picture:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to query the position of the first element in php. For more information, please follow other related articles on the PHP Chinese website!