Ahoj. 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.
Třídění chci udělat podle hodnot. Verzi php mám 5.4.16
Tuto funkci jsem zkoušel až po sort(), ale prakticky stejný výsledek ať tam dám intval nebo ne.
function myCmpFnc($a, $b)
{
if (intval($a) == intval($b)) {
return 0;
}
return ( intval($a) < intval($b)) ? -1 : 1;
}
//var_dump($img_list); 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;
var_dump($img_list);
// print_r($img_list);
To pole, které je hlouběji vnořené se nepodařilo správně uspořáadat podle hodnoty čísla.
array (size=2)
0 =>
array (size=2)
0 =>
array (size=8)
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => int 5
5 => int 6
6 => int 7
7 => int 8
1 => int 8
1 =>
array (size=2)
0 =>
array (size=12)
0 => int 1
1 => int 10
2 => int 11
3 => int 12
4 => int 2
5 => int 3
6 => int 4
7 => int 5
8 => int 6
9 => int 7
10 => int 8
11 => int 9
1 => int 12
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
array (size=12)
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
10 => int 11
11 => int 12
array (size=7)
'Mon' =>
array (size=4)
'n' => int 6
'c' =>
array (size=6)
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => int 5
5 => int 6
'Q_alternative' => boolean false
'single' => boolean true
'Tue' =>
array (size=4)
'n' => int 14
'c' => boolean false
'Q_alternative' =>
array (size=2)
0 =>
array (size=2)
...
1 =>
array (size=2)
...
'single' => boolean false
'Wed' =>
array (size=4)
'n' => int 20
'c' => boolean false
'Q_alternative' =>
array (size=2)
0 =>
array (size=2)
...
1 =>
array (size=2)
...
'single' => boolean false
'Thu' =>
array (size=4)
'n' => int 30
'c' => boolean false
'Q_alternative' =>
array (size=3)
0 =>
array (size=2)
...
1 =>
array (size=2)
...
2 =>
array (size=2)
...
'single' => boolean false
'Fri' =>
array (size=4)
'n' => int 9
'c' =>
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
'Q_alternative' => boolean false
'single' => boolean true
'Sat' =>
array (size=4)
'n' => int 10
'c' =>
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
'Q_alternative' => boolean false
'single' => boolean true
'Sun' =>
array (size=4)
'n' => int 12
'c' =>
array (size=12)
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
10 => int 11
11 => int 12
'Q_alternative' => boolean false
'single' => boolean true
Čá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.