When I implode my array I get a list that looks like this:
I need to add single quotes so it looks like:
Can this be done using PHP?
Rizier123 57.8k16 gold badges91 silver badges142 bronze badges asked Dec 23, 2015 at 17:11
Tom CanfarottaTom Canfarotta 6831 gold badge5 silver badges14 bronze badges 4 Use
answered Dec 23, 2015 at 17:32
Here is another way:
sprintf() is a clean way of wrapping the single quotes around each item in the array array_map() executes this for each array item and returns the updated array implode() then turns the updated array with into a string using a comma as glue answered Jan 14, 2018 at 20:03
It can also be as short as this:
answered Aug 17, 2020 at 14:41
Gale YaoGale Yao 831 silver badge9 bronze badges You can set the glue to
http://codepad.org/bkTHfkfx answered Dec 23, 2015 at 17:14
MusaMusa 94.7k17 gold badges113 silver badges130 bronze badges Similar to what Rizier123 said, PHP's implode method takes two arguments; the "glue" string and the "pieces" array. so,
gives you the elements separated by a comma and a space, so
gives you the elements separated by From there all you need to do is concatenate your list with single quotes on either end. answered Dec 23, 2015 at 17:20
answered Nov 20, 2019 at 14:00
1
answered Dec 28, 2020 at 9:15
You can use the method
called
You output will be something like below:
Punit Gajjar 4,5237 gold badges32 silver badges64 bronze badges answered May 22 at 21:37
|