I have this array but I want to sort it by my criteria.
I want if "country" and "top" are the same then they heve to be on one place. Slightly below give an example of what I mean.
$array = array(
array("city" => "New York", "country" => "USA", "top" => "1"),
array("city" => "London", "country" => "UK", "top" => "1"),
array("city" => "Sofia", "country" => "BG", "top" => "1"),
array("city" => "Belgrad", "country" => "SRB", "top" => "2"),
array("city" => "Varna", "country" => "BG", "top" => "2"),
array("city" => "LA", "country" => "UK", "top" => "1"),
array("city" => "Bat", "country" => "USA", "top" => "1")
);
Here is the array:
Array
(
[0] => Array
(
[city] => New York
[country] => USA
[top] => 1
)
[1] => Array
(
[city] => London
[country] => UK
[top] => 1
)
[2] => Array
(
[city] => Sofia
[country] => BG
[top] => 1
)
[3] => Array
(
[city] => Belgrad
[country] => SRB
[top] => 2
)
[4] => Array
(
[city] => Varna
[country] => BG
[top] => 2
)
[5] => Array
(
[city] => LA
[country] => USA
[top] => 1
)
[6] => Array
(
[city] => Bat
[country] => UK
[top] => 1
)
)
I want this result:
Array
(
[0] => Array
(
[0] => Array
(
[city] => New York
[country] => USA
[top] => 1
)
[1] => Array
(
[city] => LA
[country] => USA
[top] => 1
)
[2] => Array
(
[top_cities] => 2
)
)
[1] => Array
(
[0] => Array
(
[city] => London
[country] => UK
[top] => 1
)
[1] => Array
(
[city] => Bat
[country] => UK
[top] => 1
)
[2] => Array
(
[top_cities] => 2
)
)
[2] => Array
(
[0] => Array
(
[city] => Sofia
[country] => BG
[top] => 1
)
)
[3] => Array
(
[city] => Belgrad
[country] => SRB
[top] => 2
)
[4] => Array
(
[city] => Varna
[country] => BG
[top] => 2
)
)
Criteria(must match): Country Top and count how top have in this array(sum)
I will be very grateful if someone give a idea how to handle with this problem. Thanks in advance.
foreach