How to Sort Multidimensional Arrays Using PHP

How to Sort Multidimensional Arrays Using PHP

John Morris

12 лет назад

26,238 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

askela superior
askela superior - 25.07.2022 14:28

The best video for multidimensional array sorting by so far.
Bless you!

Ответить
Adrián Quintana
Adrián Quintana - 18.05.2022 11:17

Gracias 😁

Ответить
Marco Macaluso
Marco Macaluso - 13.05.2022 17:54

This is by far one of the most comprehensible and easy to understand videos that I've seen on this. And trust me, i've watched a lot over the past two days. Thank you.

Ответить
Attila Balog
Attila Balog - 14.03.2019 00:41

ohh man...i know this is an old video, but still THANK YOU!!!! you saved me lots of headache!!!! Cheers!!!

Ответить
betogm
betogm - 23.01.2019 21:28

Thank you so much, my friend. You have saved me a lot of headaches!

Ответить
La_Place
La_Place - 23.06.2018 13:03

Thank you, that is exactly what i was looking for - for hours!

Ответить
rayvn M
rayvn M - 20.03.2018 03:20

Thank you so much! I had to make slight tweak since numeric indices surfaced 'offset' errors. This is the tweak - just in case someone is running into the same issue: $b[$k] and $c[$k].

Ответить
Kabengwa Patu
Kabengwa Patu - 25.03.2017 11:05

this works great ... issue is it doesnt work with dates... because it will only look at the first number in the date.

Ответить
Gilbert Bigelow
Gilbert Bigelow - 25.12.2016 17:28

Very good tutorial! I could hear it well and clear, on topic the entire time and well thought out.

Ответить
Marcelo Ferreira Fernande Martins
Marcelo Ferreira Fernande Martins - 01.08.2016 21:37

Thank you, so much... This simple function help me a lot...

Ответить
Regis Santos
Regis Santos - 22.04.2016 17:31

Obrigado, very good!

Ответить
Dan Cacovean
Dan Cacovean - 08.11.2015 13:15

great!!!

Ответить
Georgi Georgiev
Georgi Georgiev - 28.04.2015 17:41

Thank you very much!

GOD bless you.

Ответить
Jan Hryniuk
Jan Hryniuk - 28.03.2015 20:28

Pleas read more about array_multisort.
This is the fragment of code that I write when I needed to sort multidemensional array:

<?php
    $arr =     [
                ['lname' => 'Allower',         'fname' => 'Stewart',     'profesion' => 'cheef'],
                ['lname' => 'Kovalski',        'fname' => 'John',          'profesion' => 'programmist'],
                ['fname' => 'Savige',        'fname' => 'Allan',       'profesion' => 'accounter']
               ];
               foreach($arr as $key => $val)
               {
                   $lname[$key]         = $val['lname'];
                   $fname[$key]         = $val['fname'];
                   $profesion[$key]    = $val['profesion'];
               }
    array_multisort($lname, SORT_DESC, $fname, SORT_ASC, $arr );
    echo '<pre>';
    var_dump($arr);
    echo '</pre>';
Explenations:
In array_multisort you can set numbers of arrays to sort asc or desc as a column.
In last parameter you set the name of original array that you want to sort.
Important think is that the names of arrays shuld be the same that the collumn of multidemesional array.
So what is the point of building another function in script if you got build-in ready to use function?

Ответить
Amirul Menjeni
Amirul Menjeni - 30.01.2015 07:13

You are awesome. Thanks.

Ответить
Gokul Rathod
Gokul Rathod - 15.01.2014 23:02

font size is very short...

Ответить
John Morris
John Morris - 07.05.2013 07:46

Haha thanks!

Ответить
John Morris
John Morris - 07.05.2013 07:45

No problem!

Ответить