I have an array pr($site_name_with_value) looks like this. This is the result of two combine_array.
Array(
[Ashuganj PDB] => 720
[Bagherhat PGCB] => 720
[Banani_CO] => 720
[Barapukuria PGCB] => 784
[Barishal PGCB] => 780
[Benapole_CO] => 752
[Bogura RO] => 776
[Bogura_CO(IS)] => 784
)
I have tried this to expected output.
$site_name_with_value_order = arsort($site_name_with_value);
foreach ($site_name_with_value_order as $key => $val) {
echo "$key = $val\n";
}
It returns an error message Invalid argument supplied for foreach()
First I want to sort them by value descending order. Second if the value is the same then order index by ascending.
I want to get output looks like this. But I don't know how to gain my expected output.
Array(
[Bogura_CO(IS)] => 784
[Barapukuria PGCB] => 784
[Barishal PGCB] => 780
[Bogura RO] => 776
[Benapole_CO] => 752
[Ashuganj PDB] => 720
[Bagherhat PGCB] => 720
[Banani_CO] => 720
)
arsort()doesn't return the sorted array. It returns a boolean. It modifies the original array (uses it as a reference). So you're actually passing a boolean toforeach()which is invalid.