Jump to content

[SOLVED] natcasesort help


thewooleymammoth

Recommended Posts

can anyone tell me why this isnt working???? tried it on wamp and server and for some reason the natcasesort() is just sorting it like sort() would

<?php
$dir=$_GET['dir'];


$img= scandir("$dir/");
natcasesort($img);
  $num=2;

echo"<center><table align='top' BGCOLOR='#CCCC99' cellspacing='60'><tr valign='top'><td>";
   while ($img[$num]!= null)
   {
    echo "<a href='display.php?num=$num&dir=$dir'>$img[$num]</a><br>";
    if ($num2 >= 1500)
    {
     echo "</td><td>";
     $num2=0;
    }
    $num2++;
    $num++;
   }
?>

 

ive got a link to it on my server http://fatalinjury.org/list.php?dir=pics notice lowercase letters start about half way down the list

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/125566-solved-natcasesort-help/
Share on other sites

<?php

include('menu.php');
$dir=$_GET['dir'];


$img= scandir("$dir/");
natcasesort($img);
  $num=2;
  $num2=0;

echo"<center><table align='top' BGCOLOR='#CCCC99' cellspacing='60'><tr valign='top'><td>";
   while ($img[$num]!= null)
   {
    echo "<a href='display.php?num=$num&dir=$dir'>$img[$num]</a><br>";
    if ($num2 >= 1500)
    {
     echo "</td><td>";
     $num2=0;
    }
    $num2++;
    $num++;
   }
    echo "</tr></td></table></center>";
?>

 

sorry there is the right code

The keys of the array are not changed, so when you iterate using an incrementing key, you get the original array order.

 

I recommend using a foreach() loop instead of using the $num counter in a while loop.

 

why wouldnt it be changing the order of the keys?

You should probably read the php manual page for the function you are using to learn what the function does and does not do.

 

i realize it doesn't change the keys, but why doesnt it? is there an advantage to keeping the keys? and also is there an alternative to make it so it does change the keys cause my site runs on the basis that the keys will line up

You should probably read the php manual page for the function you are using to learn what the function does and does not do.

 

i realize it doesn't change the keys, but why doesnt it? is there an advantage to keeping the keys? and also is there an alternative to make it so it does change the keys cause my site runs on the basis that the keys will line up

 

after a while of reading through the comments on http://www.php.net/natcasesort if found a comment about array_values() which solved my problem thanks for the help though

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.