Php: a method for parsing string arrays. php parses string arrays.
This example describes a php Method for parsing arrays in strings. Share it with you for your reference. The details are as follows:
<? Php $ str = "1 | Apple | 301 | peach | 501 | normal | 102 | wheat | 1002 | corn | 352 | rice | 303 | computer | 53 | MP3 | 1213 | printer | 8 "; $ strArray = explode ("\ n", $ str);/* the key is the following code */$ result = array (); foreach ($ strArray as $ item) {$ itemArray = explode ('|', $ item); $ result [$ itemArray [0] [] = $ item;} echo "<pre> "; print_r ($ result); echo "<pre>";?>
The running result is as follows:
<Pre> Array ([1] => Array ([0] => 1 | Apple | 30 [1] => 1 | peach | 50 [2] => 1 | normal | 10) [2] => Array ([0] => 2 | wheat | 100 [1] => 2 | corn | 35 [2] => 2 | rice | 30) [3] => Array ([0] => 3 | computer | 5 [1] => 3 | MP3 | 121 [2] => 3 | printer | 8 )) <pre>
I hope this article will help you with php programming.