Home > Mobile >  PHP - trim array
PHP - trim array

Time:01-06

i have a string i made it an array

my string

1 S7-6544 S 07ЯНВ22 0105 ХДТ ГСВ OK SSTOW 1М A

my array

$d=explode(' ', $Session); 

my result

enter image description here

how can i do trim in array tell me please

CodePudding user response:

You can use array_map('trim', $array) to trim all entries of the array.

$array = array_map('trim', $array);

Or, use preg_split() instead of explode :

$str = '1    S7-6544 S 07ЯНВ22 0105 ХДТ ГСВ OK  SSTOW                           1М   A';
$array = preg_split('~\s~', $str, 0, PREG_SPLIT_NO_EMPTY);
print_r($array)

Output:

(
    [0] => 1
    [1] => S7-6544
    [2] => S
    [3] => 07ЯНВ22
    [4] => 0105
    [5] => ХДТ
    [6] => ГСВ
    [7] => OK
    [8] => SSTOW
    [9] => 1М
    [10] => A
)
  •  Tags:  
  • Related