Multidimensional array how to remove a character from a given index?

Asked

Viewed 35 times

-1

The code below is the result of reading a CSV file, which transforms it into Array to treat it to create a new CSV to be imported with a new format. I want to remove the - that are in the phone numbers / cell phone.

We know that in phones / cell phones there are always 4 digits before -, but do not know how to do it to remove.

Example:

array
  0 => 
    array (size=4)
      0 => string 'Nome/Razão Social'
      1 => string 'Nome Fantasia'
      2 => string 'Tel.'
      3 => string 'Cel.'
  1 => 
    array (size=4)
      0 => string 'XXX XXXXX XXXXXXXX'
      1 => string ''
      2 => string '9123-4321'
      3 => string '7123-4312'

Thanks in advance for the help.

1 answer

0

The way it is, you just use the str_replace:

    $array = [
        ['Nome/Razão Social', 'Nome Fantasia', 'Tel.', 'Cel.'],
        ['XXX XXXXX XXXXXXXX','', '9123-4321', '7123-4312']
    ];

    $array[1] = str_replace("-", "", $array[1]); // alteração feita aqui

    print_r($array);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.