Results 1 to 3 of 3

Thread: Sorting multidimensional arrays

  1. #1

    Sorting multidimensional arrays

    Does anybody know how to sort multidimensional arrays? I followed the instructions on the book PHP and MySQL Web Development but it doesn't seem to work. The instructions are here:
    http://www.samspublishing.com/articl...&seqNum=6&rl=1

    Any other methods?

    Thanks in advance,

    Leo
    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

  2. #2

  3. #3
    Hey, thanks, i didnt know that function existed. I already read about it at the php site and tried a couple of examples, but I just can't get my code to work properly. I dinamically create an array, like this...

    PHP Code:
    $count 0;
    $handle opendir($dirEstate);
    while((
    $file readdir($handle)) !== FALSE) {
        if (
    is_dir($dirEstate $file)) continue;
        if (!
    eregi(".xml$"$file)) continue;
        
        
    $estateFile simplexml_load_file($dirEstate $file);

        if(
    $count == 0){
        
    $sortArray = array($sortArray2=array($estateFile['id'],
            
    $estateFile->mainphoto,
            
    $estateFile->address,
            
    $estateFile->city,
            
    $estateFile->state,
            
    $estateFile->zipcode,
            
    $estateFile->price,
            
    $estateFile->category,
            
    $estateFile->forlrs,
            
    $estateFile->pubdate)
            );
            
    $count++;
        }else{
            
    array_push($sortArray$sortArray2=array($estateFile['id'],
            
    $estateFile->mainphoto,
            
    $estateFile->address,
            
    $estateFile->city,
            
    $estateFile->state,
            
    $estateFile->zipcode,
            
    $estateFile->price,
            
    $estateFile->category,
            
    $estateFile->forlrs,
            
    $estateFile->pubdate)
            );
        
    $count++;
        }
    }

        
    array_multisort($sortArray[0], SORT_DESCSORT_STRING,
                        
    $sortArray[1], SORT_ASCSORT_NUMERIC);

        
    var_dump($sortArray); 
    And I get a result like this:

    PHP Code:
    array(2
        {
        [
    0]=> array(10
        { [
    0]=> object(SimpleXMLElement)#17 (1) 
        
    { [0]=> string(4"rent" } [1]=> object(SimpleXMLElement)#24 (1)
        
    { [0]=> string(36"realestate20070213101812_5_thumb.jpg" } [2]=> object(SimpleXMLElement)#33 (1) 
        
    { [0]=> string(24"realestate20070213101812" } [3]=> object(SimpleXMLElement)#21 (1) 
        
    { [0]=> string(5"Texas" } [4]=> object(SimpleXMLElement)#22 (1) 
        
    { [0]=> string(6"Laredo" } [5]=> object(SimpleXMLElement)#10 (1) 
        
    { [0]=> string(15"Condo/Townhouse" } [6]=> object(SimpleXMLElement)#19 (1) 
        
    { [0]=> string(5"90500" } [7]=> object(SimpleXMLElement)#20 (1) 
        
    { [0]=> string(5"78043" } [8]=> object(SimpleXMLElement)#16 (1) 
        
    { [0]=> string(10"2007-02-13" } [9]=> object(SimpleXMLElement)#23 (1) 
        
    { [0]=> string(11"100 Main St" }
        }
        [
    1]=> array(10
        { [
    0]=> object(SimpleXMLElement)#32 (1) 
        
    { [0]=> string(4"sale" } [1]=> object(SimpleXMLElement)#28 (1) 
        
    { [0]=> string(34"realestate20070213102231_thumb.jpg" } [2]=> object(SimpleXMLElement)#25 (1) 
        
    { [0]=> string(24"realestate20070213102231" } [3]=> object(SimpleXMLElement)#35 (1) 
        
    { [0]=> string(5"Texas" } [4]=> object(SimpleXMLElement)#29 (1) 
        
    { [0]=> string(6"Laredo" } [5]=> object(SimpleXMLElement)#31 (1) 
        
    { [0]=> string(4"Home" } [6]=> object(SimpleXMLElement)#38 (1) 
        
    { [0]=> string(6"120000" } [7]=> object(SimpleXMLElement)#30 (1) 
        
    { [0]=> string(5"78045" } [8]=> object(SimpleXMLElement)#44 (1) 
        
    { [0]=> string(10"2007-02-13" } [9]=> object(SimpleXMLElement)#37 (1) { [0]=> string(15) "10100 Center Rd" } } } 
    I want my array to be sorted by price. I already tried changing the values between the brackets and I already tried other things, but I can't get it to work.

    Can anybody give me any suggestions?

    Thanks in advance,

    Leo
    "You are playing a very dangerous game"
    "Change always is"

    Creativo Development

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012