PHP loops a string for processing. I want to do this. there is a string str & quot; 1, 3, 5, 6, 8, 9 & quot; the data in this string is ID, I want to loop them out one by one and bring them into the query statement for separate queries. although it is very simple, I just got started with php and don't know how to use it. please write the complete code. thank you, i'm Cainiao ------ solution ------------------ PHPcode $ str PHP loop a string for processing
I want to do this
There is a string str = "1, 3, 5, 6, 8, 9 ";
The data in this string is ID. I want to cycle them one by one and bring them into the query statement for separate query.
How to implement it?
Although very simple, I don't know how to use php.
Please write the complete code. thank you. I'm a Cainiao.
------ Solution --------------------
PHP code
$ Str = "1, 3, 5, 6, 8, 9"; $ str = explode (',', $ str); foreach ($ str as $ k => $ v) {echo $ v."
"; // Your other operations .}
------ Solution --------------------
Explode function. Use google
------ Solution --------------------
Why are people always asking these questions?
I think this is an attitude issue.
At least the manual is usually used to double the character string.
Even if you do not know the built-in functions of php
You can also write an algorithm yourself.
However, it is highly efficient to understand basic common functions.
Ignore me if I have any questions.
------ Solution --------------------
Top floor, very good! Kubernetes
------ Solution --------------------
$ Arr = explode (",", $ string );
Foreach ($ arr as $ value ){
Echo $ value;
}
------ Solution --------------------
PHP code
Foreach (explode (',', $ str) as $ k = >$ v) {echo "{$ k }:{$ v}
\ R \ n ";}
------ Solution --------------------
Discussion
Why are people always asking these questions?
I think this is an attitude issue.
At least the manual is usually used to double the character string.
Even if you do not know the built-in functions of php
You can also write an algorithm yourself.
However, it is highly efficient to understand basic common functions.
Ignore me if I have any questions.
------ Solution --------------------
Discussion
Reference:
Why are people always asking these questions?
I think this is an attitude issue.
At least the manual is usually used to double the character string.
Even if you do not know the built-in functions of php
You can also write an algorithm yourself.
However, it is highly efficient to understand basic common functions.
Ignore me if I have any questions.
Although it is a bit radical, it makes sense. it is recommended that you check the manual more.