1

I have this script which arranges my folders in some tags and takes only 4 items.. which is great! But I need it to take the items by the alphabet

    $counter = 0;
$directory = opendir("albums/");  
while (($item = readdir($directory)) !== false && $counter < 4) { 
    if (($item != ".") && ($item != "..")){ 
    $files[] = $item;
    //..
    $counter++;
    } 
} 

I have this script and I would like to combine or replace it with

$items = glob("albums/*", GLOB_ONLYDIR);
{
    foreach($items as $item)
    {
    //..
    }
}

How can i do it? Glob function is new to me...

Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57
Elad
  • 75
  • 2
  • 10

1 Answers1

0

To take the 4 first items

$dirs = array_slice(glob('albums/*', GLOB_ONLYDIR), 0, 4);

array_slice()

KingCrunch
  • 128,817
  • 21
  • 151
  • 173