Jump to content

Ordenar 3D array


filipex_27

Recommended Posts

Boas tenho um array do tipo:

Array
(
   [postO1] => Array
    (
	    [des1] => Array
		    (
			    [Jun] => 123
			    [s13] => 12
			    [31] => 32
		    )
	    [des2] => Array
		    (
			    [Jun] => 332
			    [s14] => 13
			    [23] => 42
		    )
	    [des3] => Array
		    (
			    [Jun] => 200
			    [s12] => 21
			    [24] => 76
		    )
    )
   [postO2] => Array
    (
	    [des1] => Array
		    (
			    [Jun] => 97
			    [s13] => 3
			    [31] => 22
		    )
	    [des2] => Array
		    (
			    [Jun] => 37
			    [s13] => 34
			    [31] => 65
		    )
	    [des3] => Array
		    (
			    [Jun] => 98
			    [s13] => 65
			    [31] => 96
		    )
    )
   [postO3] => Array
    (
	    [des1] => Array
		    (
			    [Jun] => 86
			    [s13] => 2
			    [31] => 43
		    )
	    [des2] => Array
		    (
			    [Jun] => 63
			    [s13] => 253
			    [31] => 86
		    )
	    [des3] => Array
		    (
			    [Jun] => 874
			    [s13] => 23
			    [31] => 1
		    )
    )
)

agora queria ordená-lo pelo valor da chave "Jun"...

o que já tenho é algo do género...

function max3D($item1,$item2)
{
   if ($item1['Jun'] == $item2['Jun']) return 0;
   return ($item1['Jun'] < $item2['Jun']) ? 1 : -1;
}


$postos=array('POSTO1','POSTO2','POSTO3');

foreach($postos as $pt){
usort($p[$pt], "max3D");
}


quanto executo...fico com algo do tipo...

Array
(
   [postO1] => Array
    (
	    [0] => Array
		    (
			    [Jun] => 332
			    [s14] => 13
			    [23] => 42
		    )
	    [1] => Array
		    (
			    [Jun] => 200
			    [s12] => 21
			    [24] => 76
		    )
	    [2] => Array
		    (
			    [Jun] => 123
			    [s13] => 12
			    [31] => 32
		    )
    )
   [postO2] => Array
    (
	    [0] => Array
		    (
			    [Jun] => 98
			    [s13] => 65
			    [31] => 96
		    )
	    [1] => Array
		    (
			    [Jun] => 97
			    [s13] => 3
			    [31] => 22
		    )
	    [2] => Array
		    (
			    [Jun] => 37
			    [s13] => 34
			    [31] => 65
		    )
    )
   [postO3] => Array
    (
	    [0] => Array
		    (
			    [Jun] => 874
			    [s13] => 23
			    [31] => 1
		    )
	    [1] => Array
		    (
			    [Jun] => 86
			    [s13] => 2
			    [31] => 43
		    )
	    [2] => Array
		    (
			    [Jun] => 63
			    [s13] => 253
			    [31] => 86
		    )
    )
)

ou seja para cada posto perco a designação...o que eu não queria...alguma pista? Obrigado!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.