Answer the question
In order to leave comments, you need to log in
How to remove square brackets in php response?
Hello. Here is a request
$row = json_encode($stmt->fetchAll(PDO::FETCH_OBJ));
echo "$row";
Answer the question
In order to leave comments, you need to log in
$row = json_encode(array_pop($stmt->fetchAll(PDO::FETCH_OBJ)));
/* or */
$row = json_encode($stmt->fetch());
The brackets appear because the return value of $stmt->fetchAll(PDO::FETCH_OBJ) is an array (more info: php.net/manual/en/pdostatement.fetchall.php).
Accordingly, it is enough, $stmt->fetchAll(PDO::FETCH_OBJ)[0]
but this is not entirely true, you need to add a check to see if there is a value at all.
Maybe, depending on the task, you can use fetch.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question