Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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] = "";
- $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] = "";';
- $string = substr($string, 0, -1);
- $arr = explode('; ', $string);
- $newArray = [];
- foreach($arr AS $value){
- $keyVals = explode(' = ', $value);
- preg_match_all('/^(.*?)[([0-9]+)]$/', $keyVals[0], $matches);
- $value = is_string($keyVals[1]) ? substr($keyVals[1], 1, -1) : $keyVals[1];
- $newArray[$matches[2][0]][$matches[1][0]] = $value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement