webdevask.com

Menu

  • Home
  • New
  • Add question

php - FTP and pulling item from array want to get rid of an Empty array

View Original

one text

Solution:

You can remove those entries with , comparing each name in the array to either '.' or '..', and only keeping the values that don't match:

$directory = array_filter($directory, function ($name) { 
    return !in_array($name, array('.', '..'));
});

You could also use to do the comparison, using a regex that will match a string of one or two periods:

$directory = array_filter($directory, function ($name) { 
    return !preg_match('/^\.\.?$/', $name);
});

Output (for both cases):

Array
(
    [2] => .ftpquota
    [3] => error_log
    [4] => index.php
    [5] => index2.php
)

Demo on 3v4l.org

Note if you would prefer a 0-indexed array, just use

$directory = array_values($directory);

after the call to array_filter.

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top