A
A
akgromov2019-02-01 18:13:35
JavaScript
akgromov, 2019-02-01 18:13:35

How to return the array with the smallest value?

there is such an array

$arr = [
        [
            "window" => 01,
            "services" => "Asd",
            "clients_count" => 4
        ],
        [
            "window" => 02,
            "services" => "Asd",
            "clients_count" => 3
        ]
    ];

need to come back
[
            "window" => 02,
            "services" => "Asd",
            "clients_count" => 3
 ]

Sort by clients_count

Answer the question

In order to leave comments, you need to log in

4 answer(s)
W
web-mechanic, 2016-06-26
@amfetamine

check if the bootstrap.min.js script is included
, this method is there

V
Vladimir, 2016-06-26
@Vovchikvoin

What kind of method is this in jekvery? Where did you see him.

E
Evgeny Kylin, 2019-02-01
@akgromov

function sort_my_arr($a, $b){
     return ($a['clients_count'] < $b['clients_count']) ? -1 : 1;
}
usort($arr, 'sort_my_arr');
array_shift($arr);

V
Vitaliy Orlov, 2019-02-01
@orlov0562

<?php
$arr = [
        [
            "window" => 01,
            "services" => "Asd",
            "clients_count" => 4
        ],
        [
            "window" => 02,
            "services" => "Asd",
            "clients_count" => 3
        ]
    ];

usort($arr, function($a, $b){
    return $a['clients_count'] > $b['clients_count'];
});

print_r($arr[0]);

Array ( [window] => 2 [services] => Asd [clients_count] => 3 )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question