拜,代碼長老,執行opendir功能讓我多陣列,而不只是一個
我在尋求掌握PHP的法術,現在需要在殺害你的幫助一個強有力的野獸。
我正在PHP中創建一個REST API。其中一個函數是一個GET,它返回一個dir中的png列表。但是不是返回一個數組,而是返回多個數組(每次迭代一個?)。
我想:
["1.png","2.png","3.png"]
但我發現了:
["1.png"]["1.png","2.png"]["1.png","2.png","3.png"]
我提出我的可憐的功能蔑視和羞辱:
function getPics() {
$pic_array = Array();
$handle = opendir('/srv/dir/pics');
while (false !== ($file = readdir($handle))) {
if ($file!= "." && $file!= ".." &&!is_dir($file)) {
$namearr = explode('.',$file);
if ($namearr[count($namearr)-1] == 'png') $pic_array[] = $file;
}
echo json_encode($pic_array);
}
closedir($handle);
}
非常感謝您的糾正和提示。我將從此堅持正確的縮進。 – playeren 2012-02-18 12:43:06