Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

php multidimensional array sorting using inner value

I have the following array:

Array
(
    [ret_code] => 0
    [ret_msg] => OK
    [result] => Array
        (
            [0] => Array
                (
                    [symbol] => 10000NFTUSDT
                    [bid_price] => 0.004085
                    [ask_price] => 0.004095
                    [last_price] => 0.004085
                    [last_tick_direction] => MinusTick
                    [prev_price_24h] => 0.004090
                    [price_24h_pcnt] => -0.001222
                    [high_price_24h] => 0.004120
                    [low_price_24h] => 0.004040
                )

            [1] => Array
                (
                    [symbol] => 1000BONKUSDT
                    [bid_price] => 0.002089
                    [ask_price] => 0.002092
                    [last_price] => 0.002093
                    [last_tick_direction] => PlusTick
                    [prev_price_24h] => 0.001587
                    [price_24h_pcnt] => 0.31884
                    [high_price_24h] => 0.002396
                    [low_price_24h] => 0.001553
                )

            [2] => Array
                (
                    [symbol] => 1000BTTUSDT
                    [bid_price] => 0.000628
                    [ask_price] => 0.000629
                    [last_price] => 0.000628
                    [last_tick_direction] => ZeroMinusTick
                    [prev_price_24h] => 0.000623
                    [price_24h_pcnt] => 0.008025
                    [high_price_24h] => 0.000631
                    [low_price_24h] => 0.000622
                )

        )

    [ext_code] => 
    [ext_info] => 
    [time_now] => 1673109990.331754
)

How could I sort this array by the [price_24h_pcnt] nested value?

My ideal output would be simpler array such as… (‘1000BONKUSDT’, ‘10000NFTUSDT’, ‘1000BTTUSDT’)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried using array_column but failed to successfully navigate the nesting. Thank you for any help.

>Solution :

$key_values = array_column($arrayName, 'price_24h_pcnt'); 
array_multisort($key_values, SORT_ASC, $arrayName);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading