如何隐藏空白数组并只保留数组的value/name?

How to hide blank array and just leave array's value/name?

我正在使用 jquery 自动完成插件。如何隐藏空白数组并只保留数组的value/name?例如

Html :

 <script type="text/javascript">

    $(function() {

        $("#ac5").autocomplete('search.php', {
            minChars: 1,

        });

       });

        </script>
    <form>
            <input type="text" id="ac5">
        </form>

Php :

/*
 * Load sample data
 */

$dir    = '../image/imagefiles/';
$images = scandir($dir);




/*
 * Results array
 */
$results = $images;

/*
 * Autocomplete formatter
 */
function autocomplete_format($results) {
    foreach ($results as $result) { 
        echo $result;
    }
}

/*
 * Output format
 */
$output = 'autocomplete';
if (isset($_GET['output'])) {
    $output = strtolower($_GET['output']);
}

/*
 * Output results
 */
if ($output === 'json') {
    echo json_encode($results);
} else {
    echo autocomplete_format($results);
}

自动完成的输出:...Dj_Etrom_Remix1.jpgDj_Etrom_Remix2.jpgDj_Etrom_Remix3.jpg 它在同一行中显示所有文件名,但我想这样做 Dj Etrom Remix.jpg

问题是 your autocomplete_format 函数,它只是 echo 数组的每个元素...

你可以在里面做任何你想做的事。
如果您希望所有文件都换行,请使用 echo $result."\n";
如果您希望它出现在 html 页面中,请使用 echo $result."<br/>";
如果您想用逗号分隔它们,请使用 echo $result.", ";...

但是使用 jQuery 自动完成,您应该将其作为 json 数组发送...