I'm trying to save an array in a MySQL table, I serialize it and it shows something like a:3:{s:8:"One";s:1:"1";s:6:"Two";s:2:"2";
... but I don't want it like this, I want something like this {One = 1, Two = 2}
or something similar without those weird characters "a:4", "s:3"
, I was trying to look up and I was told to deserialize, but it isn't the solution i'm looking for as it shows something like {1,2}
. Is there a way to make it look like I'm saying?
This is what I tried to do to deserialize:
$r9 = array("One"=>"1", "Two"=>"2", "Three"=>"3");
$serializedArray = serialize($r9);
$decoded = unserialize($serializedArray);
$respuestaCompleta = $cadena_equipo = implode(",", $decoded);;
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "INSERT INTO encuesta (id, pregunta, respuesta) VALUES ('$id', '$q9', '$respuestaCompleta')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
mysqli_close($conn);