How to trim white spaces of array values in php

后端 未结 12 1401
旧巷少年郎
旧巷少年郎 2020-11-28 19:30

I have an array as follows

$fruit = array(\'  apple \',\'banana   \', \' , \',     \'            cranberry \');

I want an array which conta

12条回答
  •  时光取名叫无心
    2020-11-28 20:14

    function trimArray(&$value) 
    { 
        $value = trim($value); 
    }
    $pmcArray = array('php ','mysql ', ' code ');
    array_walk($pmcArray, 'trimArray');
    

    by using array_walk function, we can remove space from array elements and elements return the result in same array.

提交回复
热议问题