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

藏色散人
藏色散人Original
2022-01-06 10:29:103376browse

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.

How to query the position of the first element in php

#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:

How to query the position of the first element in php

Declare the file type and encoding for PHP to interact with the browser, as shown in the figure:

How to query the position of the first element in php

Input code: $str = 'abcdef';

How to query the position of the first element in php

Use the strpos() function to find the position where the character 'a' first appears, as shown in the figure:

How to query the position of the first element in php

Use the var_dump() function to output the return value $pos, as shown in the picture:

How to query the position of the first element in php

Run the web page, you can see that the index value of character 'a' is 0, as shown in the picture:

How to query the position of the first element in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn