Skip to content
Advertisement

Convert String containing commas to array

I am trying to convert a String

to an array

By doing so it gives me an error when trying to fetch data on MySQL

However, if I manually set the array as $array = array('1', '2', '3') it doesn’t give an error when fetching a data, is there a way to convert the string to the array so the fetching doesn’t give out an error? Because what I am trying to do is some data will be going to be passed to this file, where it will be fetched as a String, but later want to convert it to an array. I also tried removing the quotation mark from the String and it still gives the same error str_replace('"', "", $string); using this inside of the array.

Advertisement

Answer

if you remove the quotes around the id’s, assuming the id column is a integer column

RESULT

Of course a simpler way would be to simply do

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement