Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. City[0] = "Elghorashi";
  2. State[0] = "";
  3. ZipCode[0] = "";
  4. CCity[0] = "Elghorashi";
  5. CState[0] = "";
  6. CZipCode[0] = "";
  7. City[1] = "Abugibha";
  8. State[1] = "";
  9. ZipCode[1] = "";
  10. CCity[1] = "Abugibha";
  11. CState[1] = "";
  12. CZipCode[1] = "";
  13.  
  14. $string = 'City[0] = "Elghorashi"; State[0] = ""; ZipCode[0] = ""; CCity[0] = "Elghorashi"; CState[0] = ""; CZipCode[0] = ""; City[1] = "Abugibha"; State[1] = ""; ZipCode[1] = ""; CCity[1] = "Abugibha"; CState[1] = ""; CZipCode[1] = "";';
  15. $string = substr($string, 0, -1);
  16.  
  17. $arr = explode('; ', $string);
  18. $newArray = [];
  19. foreach($arr AS $value){
  20. $keyVals = explode(' = ', $value);
  21. preg_match_all('/^(.*?)[([0-9]+)]$/', $keyVals[0], $matches);
  22. $value = is_string($keyVals[1]) ? substr($keyVals[1], 1, -1) : $keyVals[1];
  23. $newArray[$matches[2][0]][$matches[1][0]] = $value;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement