나는 Zend_DB 쿼리에서 반환 된 배열을 json_encode하려고합니다.PHP 배열을 객체가 아닌 JSON 배열로 인코딩하는 방법은 무엇입니까?
위해서 var_dump를 제공합니다. (수동 0 회원이 사진을 변경하지 않습니다 추가)처럼
array(3) {
[1]=>
array(3) {
["comment_id"]=>
string(1) "1"
["erasable"]=>
string(1) "1"
["comment"]=>
string(6) "test 1"
}
[2]=>
array(3) {
["comment_id"]=>
string(1) "2"
["erasable"]=>
string(1) "1"
["comment"]=>
string(6) "test 1"
}
[3]=>
array(3) {
["comment_id"]=>
string(1) "3"
["erasable"]=>
string(1) "1"
["comment"]=>
string(6) "jhghjg"
}
}
인코딩 된 문자열이 같습니다
{"1":{"comment_id":"1","erasable":"1","comment":"test 1"},
"2":{"comment_id":"2","erasable":"1","comment":"test 1"},
"3":{"comment_id":"3","erasable":"1","comment":"jhghjg"}}
내가해야 할 것은 :
[{"comment_id":"1","erasable":"1","comment":"test 1"},
{"comment_id":"2","erasable":"1","comment":"test 1"},
{"comment_id":"3","erasable":"1","comment":"jhghjg"}]
php.ini/json_encode 문서에서 다음과 같이 표시됩니다.
+1 # 배열이 키를 0으로 시작되지되지 배열. phps는 잘못되었지만 어레이/해시의 별난 자식을 사랑합니다. 제대로 작동하지 않습니다. –
코드가 Zend_DB 쿼리 결과로 반환하는 것입니다. –
내가 말했듯이, 배열로 만들지 않아 숫자 키가있는 해시가됩니다.이 경우 숫자가 0 인 키가 0에 가까워집니다. 데이터베이스의 데이터에있는 것이기 때문에 시작하십시오. –