Array_map and crop without cropping a space from values

This function below returns a string of values ​​separated by commas

$key_1_value = get_post_meta(422,'keywords',true);

The output in my browser looks like this: red, white, blue, blue two , green, yellow, purple, magenta , cyan, black

I am trying to trim the space before and after all the values.

So I used this code to try to trim spaces, but it is still there. Why doesn't this crop the values?

 $test = array($key_1_value); $trimmed_array=array_map('trim',$test); print_r($trimmed_array); 
+4
source share
1 answer

$key_1_value is a string representation, not an array or a $key_1_value string, you should blow it up in the elements of the array, and not just put it inside the array call, then it becomes a suitable array

 $test = explode(",",$key_1_value); $trimmed_array=array_map('trim',$test); print_r($trimmed_array); 
+18
source

Source: https://habr.com/ru/post/1497452/


All Articles