Help in array sorting problem

Discussion in 'PHP' started by lovelyThumbsUp, Oct 7, 2008.

  1. #1
    :confused::confused::confused:
    First of all, thanks for everyone willing to helps me out~!

    OK here is my question:

    I got three arrays (listed below), I am tried to find a way out to sort these arrays by "clipa", "clipb", "clipc", "clipd", which means, if I choose "clipa", all the arrays with "clipa =>1" will go on top of the array( some resort here) and print out in priority.


    For example:

    choosed: clipa

    out print:

    1) id = 0060
    2) id = 0062
    3) id = 0061


    choosed: clipc

    out print:


    1) id = 0060
    2) id = 0061
    3) id = 0062


    -----------------------------------------------------------------
    Array 1
    (
    [id] => 0060
    [content] => Array
    (
    [clipa] => 1
    [clipb] =>
    [clipc] => 1
    )

    )


    Array 2
    (
    [id] => 0061
    [content] => Array
    (
    [clipa] =>
    [clipb] => 1
    [clipc] => 1
    )

    )

    Array 3
    (
    [id] => 0062
    [content] => Array
    (
    [clipa] => 1
    [clipb] =>
    [clipc] =>
    )

    )

    ---------------------------------------------------------------

    Is there anyone have any idea how to do this? Or which way should I looking into?

    Thanks Thanks Thanks

    L
     
    lovelyThumbsUp, Oct 7, 2008 IP
  2. gzav

    gzav Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could you please put more effort into writing a description of what you want done, and use the
     brackets around your code.
    Code (markup):
     
    gzav, Oct 7, 2008 IP
  3. lovelyThumbsUp

    lovelyThumbsUp Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    First of all, thanks for everyone willing to helps me out~!

    
    
    $test = array();
    
    $test[0]  = array 
    (
     	 [id] => 0001
         [content] => array
    	 (
    		[clipA_exsiting] => "yes"
    		[clipB_exsiting] => "no" 
    	    [clipC_exsiting] => "yes"
         )
    
    }
    
    $test[1]  = array 
    (
     	 [id] => 0002
         [content] => array
    	 (
    		[clipA_exsiting] => "no" 
    		[clipB_exsiting] => "yes"
    	    [clipC_exsiting] => "yes"
         )
    
    }
    
    
    $test[2]  = array 
    (
     	 [id] => 0003
         [content] => array
    	 (
    		[clipA_exsiting] => "yes"
    		[clipB_exsiting] => "no"
    	    [clipC_exsiting] => "no"
         )
    
    }
    
    
    // Need Help for sorting the array and print out here
    
    
    PHP:
    I am looking to get this out put:


    if user choose sort content by ClipA:

    id ......... ClipA ......... ClipB ......... ClipC
    0001 ......... yes ......... no ......... yes
    0003 ......... yes ......... no ......... no
    0002 ......... no ......... yes ......... yes


    if user choose sort content by ClipB:
    id ......... ClipA ......... ClipB ......... ClipC
    0002 ......... no ......... yes ......... yes
    0001 ......... yes ......... no ......... yes
    0003 ......... yes ......... no ......... no


    if user choose sort content by ClipC:
    id ......... ClipA ......... ClipB ......... ClipC
    0001 ......... yes ......... no ......... yes
    0002 ......... no ......... yes ......... yes
    0003 ......... yes ......... no ......... no



    Therefore, basicly I just want to sort this array $test by the sub-array $test[x][$content] base on user selection.

    Am I make myself clear?
     
    lovelyThumbsUp, Oct 7, 2008 IP
  4. lovelyThumbsUp

    lovelyThumbsUp Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Finnally I got it. Thanks all
     
    lovelyThumbsUp, Oct 7, 2008 IP