2013-06-29 3 views
1

에서 PHP의 어레이를 통과 할 때에 삽입 된 단어 '배열'얻기 ...I 다음 PHP 코드를 포함하는 웹 페이지를 생성 한 JSON

$brandArray = JSON_decode(DatabaseInterface::getBrands(), true); 
sort($brandArray); 
for ($loop=0; $loop < sizeof($brandArray); $loop++) { 
    echo "<option>$brandArray[$loop]</option>"; 
} 

함수 DatabaseInterface 관련 비트 :: getBrands은 여기 ...

$query = "SELECT psBrandName from brands"; 
$result = mysqli_query($con, $query) or die ("Couldn't execute query. ".mysqli_error($con)); 

$resultArray[] = array(); 

while ($row = mysqli_fetch_assoc($result)) { 

    extract($row); 
    $resultArray[] = $psBrandName; 

} 

return json_Encode($resultArray); 

모든 것은 내가 웹 페이지에 출력을 볼 때, 목록의 첫 번째 항목 단어 데이터베이스에 밤은 '배열'이 (있다, 변태,를 제외하고 잘 작동한다. 어느 아이디어?

+0

왜이 물건을'json_encode' (-ing)하고 있습니까? – DaGardner

+0

다른 곳에서 javascript를 사용하여 동일한 기능을 호출하므로 범용 형식으로 출력해야했습니다. –

답변

3

$resultArray[] = array()은 빈 배열을 $resultArray 배열로 푸시하는 것을 의미합니다. 대괄호를 제거하십시오.

관련 문제