Autor Zpráva
Hledám pomoc
Profil *
Poradíte mi proč se mi nedaří seřadit hodnoty v poli? Je to pole hodně strukturované, takže var_dump jsem udělal jen na jednotlivé části, které jsem třídil.
array (size=3)
  0 => 
    array (size=2)
      0 => 
        array (size=10)
          0 => int 1
          1 => int 10
          2 => int 2
          3 => int 3
          4 => int 4
          5 => int 5
          6 => int 6
          7 => int 7
          8 => int 8
          9 => int 9
      1 => int 10
  1 => 
    array (size=2)
      0 => 
        array (size=10)
          0 => int 1
          1 => int 10
          2 => int 2
          3 => int 3
          4 => int 4
          5 => int 5
          6 => int 6
          7 => int 7
          8 => int 8
          9 => int 9
      1 => int 10
  2 => 
    array (size=2)
      0 => 
        array (size=10)
          0 => int 1
          1 => int 10
          2 => int 2
          3 => int 3
          4 => int 4
          5 => int 5
          6 => int 6
          7 => int 7
          8 => int 8
          9 => int 9
      1 => int 10

array (size=9)
  0 => int 1
  1 => int 2
  2 => int 3
  3 => int 4
  4 => int 5
  5 => int 6
  6 => int 7
  7 => int 8
  8 => int 9

array (size=10)
  0 => int 1
  1 => int 2
  2 => int 3
  3 => int 4
  4 => int 5
  5 => int 6
  6 => int 7
  7 => int 8
  8 => int 9
  9 => int 10

Tuto funkci jsem zkopíroval ze stránky php, ale upravil jsem ji aby převáděla string na int. Ale toto by nemělo být třeba, protože hodnoty ukládané do pole jsem už převedl na int jak vidíte z výpisu var_dump. Původně se jednalo o čísla souborů načtených z adresáře. Nejdříve jsem zkoušel obyčejný sort.

Třídění chci udělat podle hodnot. Verzi php mám 5.4.16
foreach ($img_list as $k => $v):
  if ($img_list[$k]['c']):
    usort($img_list[$k]['c'],"myCmpFnc");
    var_dump($img_list[$k]['c']);
  else:  
    for($i=0;$i<count($img_list[$k]['Q_alternative']);$i++)
      usort($img_list[$k]['Q_alternative'][$i],"myCmpFnc");
    var_dump($img_list[$k]['Q_alternative']);  
      
  endif;    
endforeach;



Část print_r skoro celého pole.
    [Wed] => Array
        (
            [n] => 20
            [c] => 
            [Q_alternative] => Array
                (
                    [0] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 1
                                    [1] => 2
                                    [2] => 3
                                    [3] => 4
                                    [4] => 5
                                    [5] => 6
                                    [6] => 7
                                    [7] => 8
                                )

                            [1] => 8
                        )

                    [1] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 1
                                    [1] => 10
                                    [2] => 11
                                    [3] => 12
                                    [4] => 2
                                    [5] => 3
                                    [6] => 4
                                    [7] => 5
                                    [8] => 6
                                    [9] => 7
                                    [10] => 8
                                    [11] => 9
                                )

                            [1] => 12
                        )

                )

            [single] => 
        )

    [Thu] => Array
        (
            [n] => 30
            [c] => 
            [Q_alternative] => Array
                (
                    [0] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 1
                                    [1] => 10
                                    [2] => 2
                                    [3] => 3
                                    [4] => 4
                                    [5] => 5
                                    [6] => 6
                                    [7] => 7
                                    [8] => 8
                                    [9] => 9
                                )

                            [1] => 10
                        )

                    [1] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 1
                                    [1] => 10
                                    [2] => 2
                                    [3] => 3
                                    [4] => 4
                                    [5] => 5
                                    [6] => 6
                                    [7] => 7
                                    [8] => 8
                                    [9] => 9
                                )

                            [1] => 10
                        )

                    [2] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 1
                                    [1] => 10
                                    [2] => 2
                                    [3] => 3
                                    [4] => 4
                                    [5] => 5
                                    [6] => 6
                                    [7] => 7
                                    [8] => 8
                                    [9] => 9
                                )

                            [1] => 10
                        )

                )

            [single] => 
        )

    [Fri] => Array
        (
            [n] => 9
            [c] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                    [5] => 6
                    [6] => 7
                    [7] => 8
                    [8] => 9
                )

            [Q_alternative] => 
            [single] => 1
        )

    [Sat] => Array
        (
            [n] => 10
            [c] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                    [5] => 6
                    [6] => 7
                    [7] => 8
                    [8] => 9
                    [9] => 10
                )

            [Q_alternative] => 
            [single] => 1
        )

    [Sun] => Array
        (
            [n] => 12
            [c] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                    [4] => 5
                    [5] => 6
                    [6] => 7
                    [7] => 8
                    [8] => 9
                    [9] => 10
                    [10] => 11
                    [11] => 12
                )

            [Q_alternative] => 
            [single] => 1
        )

)

Něco uspořádané je a něco ne. Tak nevím co s tím.
Hledám pomoc
Profil *
Vyřešeno. V druhé větvi jsem nesprávně odkazoval, resp. neodkazoval na potřebné pole, které se mělo třídit.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0