The value of a PHP code trim ($ _ POST ['tag']) is: 11, Hello | 12, Hello | 13, Hello | 14, good | 15, let's make the following five values equal to $ tagsql ['tag1'] = 11 $ tagsql ['tag2'] = 12 $ tagsql ['tag3'] = 13 $ tagsql [' tag4'] = 14 $ tagsql [find a PHP code
Trim ($ _ POST ['tag']) value: 11, Hello | 12, he is good | 13, I am good | 14, good | 15, hello everyone
Make the following five values equal
$ Tagsql ['tag1'] = 11
$ Tagsql ['tag2'] = 12
$ Tagsql ['tag3'] = 13
$ Tagsql ['tag4'] = 14
$ Tagsql ['tag5'] = 15
How should I write the code? thank you!
------ Solution --------------------
The cycle of old scalpers
PHP code
$ Str = '11, Hi | 12, Hi | 13, Hi | 14, good | 15, good guys '; $ arr = array (); if (! Empty ($ str) {preg_match_all ('/(\ d {2})/', $ str, $ match); $ I = 0; foreach ($ match [1] as $ value) {++ $ I; $ arr ['tag '. $ I] = $ value ;}} else {for ($ I = 1; $ I <6; $ I ++) {$ arr ['tag '. $ I] = 0 ;}}