Im using the following code to import a csv that has two columns – account & phone:
$csv = array();
$file = fopen('import.csv', 'r');
while (($result = fgetcsv($file)) !== false)
{
$csv[] = $result;
}
fclose($file);
The results look something like:
Array
(
[0] => Array
(
[0] => 5182334
[1] => (360) 293-7786
)
[1] => Array
(
[0] => 8372855
[1] => (360) 755-3237
)
[2] => Array
(
[0] => 8373250
[1] => (360) 873-8853
)
[3] => Array
(
[0] => 8373226
[1] => (360) 588-1905
)
)
What I need to do is loop through the array and clean up the phone numbers removing spaces, parans, etc. I know how to do the clean up but can’t figure out how to loop through the array to do said cleaning.
You can use
array_mapandpreg_replacefor example.Or directly in loading phase: