R
R
Roman Yakushev2015-11-02 09:59:18
PHP
Roman Yakushev, 2015-11-02 09:59:18

How to make ksort work with a 2D array?

If I make an array like this:

$mysites[$sitedetails->blogname]['blog_id'] = $sitel['blog_id'];
$mysites[$sitedetails->blogname]['url'] = 'http://'.$sitel['domain'].$sitel['path'];
$mysites[$sitedetails->blogname]['blogname'] = $sitedetails->blogname;

And then I sort:
ksort($mysites);//сортируем по ключу
Everything sorts normally. But here I decided to group the array differently. And in general from two-dimensional to make three-dimensional.
It turned out like this:
$bycountry[$country][$sitedetails->blogname]['blog_id'] = $sitel['blog_id'];
$bycountry[$country][$sitedetails->blogname]['url'] = 'http://'.$sitel['domain'].$sitel['path'];
$bycountry[$country][$sitedetails->blogname]['blogname'] = $sitedetails->blogname;

Well, as I understand it, I need to sort now like this:
foreach ($bycountry as $country) {
    ksort($country);
}

But nothing is sorted, no warnings are issued. How to sort the second level of the array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-02
@CanVas

foreach ($bycountry as &$country) {
    ksort($country);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question