Jump to content

ShortSchoolBus

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ShortSchoolBus's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. My intention is to use the filename to determine it's position/depth within a list. Example - <ul> <li>page_1.php</li> <li>page_2.php <ul> <li>page_2-1.php</li> <li>page_2-2.php</li> </ul> </li> <li>page_3.php <ul> <li>page_3-1.php</li> </ul> </li> </ul> If anyone has a suggestion for an efficient method for this, please post.
  2. Yes, that's a bit tidier than mine. Thanks for taking the time to post your replies.
  3. I came up with a solution, but it's not very efficient $pages = array('page_1.php', 'page_2-1.php', 'page_2-2-1.php', 'page_2-2.php', 'page_2.php'); $pos_array = array(); foreach ($pages as $page) { $page_name = substr($page, 0, strpos($page, ".php")); $parts = explode("_",$page_name); $position_string = $parts[1]; array_push($pos_array,$position_string); } sort($pos_array); $page_array = array(); foreach ($pos_array as $pos) { foreach ($pages as $page) { $page_name = substr($page, 0, strpos($page, ".php")); $parts = explode("_",$page_name); $position_string = $parts[1]; if($pos == $position_string){ array_push($page_array,$page); } } } $pages = $page_array; Output: [0] => page_1.php [1] => page_2.php [2] => page_2-1.php [3] => page_2-2.php [4] => page_2-2-1.php
  4. You're right. More specifically, this is what I was trying to sort array('page_1.php', 'page_2-1.php', 'page_2-2-1.php', 'page_2-2.php', 'page_2.php');
  5. No, actually, regular sort will return the same array('1', '2-1', '2-2-1', '2-2', '2', '3-1', '3'); This is how a file system is sorted by default, but I need the result to be array('1', '2', '2-1', '2-2', '2-2-1', '3', '3-1');. I hope you understand what I mean.
  6. Hi, I'm having some difficulty with this and was hoping someone can show me an efficient way to sort an array such as this array('1', '2-1', '2-2-1', '2-2', '2', '3-1', '3'); to array('1', '2', '2-1', '2-2', '2-2-1', '3', '3-1'); with no length restrictions. eg., 3-3-2-2-1 or 4-5-4-3-3-2-1 Thanks in advance for your help.
×
×
  • 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.