I’m creating an array from a string with comma separated values
$result = "apple, hello word, 80, apple";
$result = str_getcsv($result); //create array
$result = array_filter(array_map('trim', $result)); //remove whitespaces
Some characters in a value have spaces between them, like hello world and I want to replace the spaces with a dash (to make the the string URL friendly.) Example: hello-world
I thought of iterating through the array using str_replace but can it be done better using array_map like I’m doing to trim?
str_replacecan work directly on arrays as well:This will have the same result as the less readable
Both are also equivalent to the classic