Sorting went fail for arrayArray is duplicating the results?Correct syntax for multiple category ID's in arrayHow to get array value in post?shorthand array declaration causing errorArray ManipulationMagento 2.1.9 broken sortingHow to implode a array objectNeed to get array valuesHow to Find out where it Is made Breadcrumb Array in Magento 2.3.1Something went wrong while saving the file(s)

What is the fastest method to figure out which keys contain certain notes?

Frame failure sudden death?

C++ Arduino IDE receiving garbled `char` from function

What's up with this leaf?

At what point in time did Dumbledore ask Snape for this favor?

What is the actual quality of machine translations?

Generate a Graeco-Latin square

Why is only the fundamental frequency component said to give useful power?

How do governments keep track of their issued currency?

Are there any important biographies of nobodies?

An average heaven where everyone has sexless golden bodies and is bored

How to construct an hbox with negative height?

What is wrong with this proof that symmetric matrices commute?

What to do when surprise and a high initiative roll conflict with the narrative?

Second (easy access) account in case my bank screws up

How to return a security deposit to a tenant

Preventing employees from either switching to competitors or opening their own business

Recommended tools for graphs and charts

Taxi Services at Didcot

Déjà vu, again?

Logarithm of exponential

How to signal to my players that the following part is supposed to be played on fast forward?

How to handle self harm scars on the arm in work environment?

Were Alexander the Great and Hephaestion lovers?



Sorting went fail for array


Array is duplicating the results?Correct syntax for multiple category ID's in arrayHow to get array value in post?shorthand array declaration causing errorArray ManipulationMagento 2.1.9 broken sortingHow to implode a array objectNeed to get array valuesHow to Find out where it Is made Breadcrumb Array in Magento 2.3.1Something went wrong while saving the file(s)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am having the array of color attribute options...



I would like to sort the array based on 'store0' key...



I have used multisort and usort but its not working



[821] => Array
(
[checked] =>
[intype] => radio
[id] => 969
[sort_order] => 513
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow - KID
[defaultswatch0] =>
[swatch0] =>
)

[822] => Array
(
[checked] =>
[intype] => radio
[id] => 207
[sort_order] => 309
[store1] => Yellow Beige - Chroma 1 ½
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow Beige - Chroma 1 ½
[defaultswatch0] =>
[swatch0] =>
)

[823] => Array
(
[checked] =>
[intype] => radio
[id] => 857
[sort_order] => 403
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-RAIN HAT BOB
[defaultswatch0] =>
[swatch0] =>
)

[824] => Array
(
[checked] =>
[intype] => radio
[id] => 860
[sort_order] => 406
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN
[defaultswatch0] =>
[swatch0] =>
)

[825] => Array
(
[checked] =>
[intype] => radio
[id] => 851
[sort_order] => 400
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN1
[defaultswatch0] =>
[swatch0] =>
)

[826] => Array
(
[checked] =>
[intype] => radio
[id] => 29
[sort_order] => 310
[store1] => Zebra
[defaultswatch1] =>
[swatch1] =>
[store0] => Zebra
[defaultswatch0] =>
[swatch0] =>
)

[827] => Array
(
[checked] =>
[intype] => radio
[id] => 1383
[sort_order] => 830
[store1] => abstract
[defaultswatch1] =>
[swatch1] =>
[store0] => abstract
[defaultswatch0] =>
[swatch0] =>
)

[828] => Array
(
[checked] =>
[intype] => radio
[id] => 1382
[sort_order] => 829
[store1] => caol color
[defaultswatch1] =>
[swatch1] =>
[store0] => caol color
[defaultswatch0] =>
[swatch0] =>
)

[829] => Array
(
[checked] =>
[intype] => radio
[id] => 1381
[sort_order] => 829
[store1] => cool color
[defaultswatch1] =>
[swatch1] =>
[store0] => cool color
[defaultswatch0] =>
[swatch0] =>
)









share|improve this question






















  • I know its a simple question .. but something went wrong...

    – 1990rk4
    May 30 at 6:28

















0















I am having the array of color attribute options...



I would like to sort the array based on 'store0' key...



I have used multisort and usort but its not working



[821] => Array
(
[checked] =>
[intype] => radio
[id] => 969
[sort_order] => 513
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow - KID
[defaultswatch0] =>
[swatch0] =>
)

[822] => Array
(
[checked] =>
[intype] => radio
[id] => 207
[sort_order] => 309
[store1] => Yellow Beige - Chroma 1 ½
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow Beige - Chroma 1 ½
[defaultswatch0] =>
[swatch0] =>
)

[823] => Array
(
[checked] =>
[intype] => radio
[id] => 857
[sort_order] => 403
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-RAIN HAT BOB
[defaultswatch0] =>
[swatch0] =>
)

[824] => Array
(
[checked] =>
[intype] => radio
[id] => 860
[sort_order] => 406
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN
[defaultswatch0] =>
[swatch0] =>
)

[825] => Array
(
[checked] =>
[intype] => radio
[id] => 851
[sort_order] => 400
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN1
[defaultswatch0] =>
[swatch0] =>
)

[826] => Array
(
[checked] =>
[intype] => radio
[id] => 29
[sort_order] => 310
[store1] => Zebra
[defaultswatch1] =>
[swatch1] =>
[store0] => Zebra
[defaultswatch0] =>
[swatch0] =>
)

[827] => Array
(
[checked] =>
[intype] => radio
[id] => 1383
[sort_order] => 830
[store1] => abstract
[defaultswatch1] =>
[swatch1] =>
[store0] => abstract
[defaultswatch0] =>
[swatch0] =>
)

[828] => Array
(
[checked] =>
[intype] => radio
[id] => 1382
[sort_order] => 829
[store1] => caol color
[defaultswatch1] =>
[swatch1] =>
[store0] => caol color
[defaultswatch0] =>
[swatch0] =>
)

[829] => Array
(
[checked] =>
[intype] => radio
[id] => 1381
[sort_order] => 829
[store1] => cool color
[defaultswatch1] =>
[swatch1] =>
[store0] => cool color
[defaultswatch0] =>
[swatch0] =>
)









share|improve this question






















  • I know its a simple question .. but something went wrong...

    – 1990rk4
    May 30 at 6:28













0












0








0








I am having the array of color attribute options...



I would like to sort the array based on 'store0' key...



I have used multisort and usort but its not working



[821] => Array
(
[checked] =>
[intype] => radio
[id] => 969
[sort_order] => 513
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow - KID
[defaultswatch0] =>
[swatch0] =>
)

[822] => Array
(
[checked] =>
[intype] => radio
[id] => 207
[sort_order] => 309
[store1] => Yellow Beige - Chroma 1 ½
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow Beige - Chroma 1 ½
[defaultswatch0] =>
[swatch0] =>
)

[823] => Array
(
[checked] =>
[intype] => radio
[id] => 857
[sort_order] => 403
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-RAIN HAT BOB
[defaultswatch0] =>
[swatch0] =>
)

[824] => Array
(
[checked] =>
[intype] => radio
[id] => 860
[sort_order] => 406
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN
[defaultswatch0] =>
[swatch0] =>
)

[825] => Array
(
[checked] =>
[intype] => radio
[id] => 851
[sort_order] => 400
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN1
[defaultswatch0] =>
[swatch0] =>
)

[826] => Array
(
[checked] =>
[intype] => radio
[id] => 29
[sort_order] => 310
[store1] => Zebra
[defaultswatch1] =>
[swatch1] =>
[store0] => Zebra
[defaultswatch0] =>
[swatch0] =>
)

[827] => Array
(
[checked] =>
[intype] => radio
[id] => 1383
[sort_order] => 830
[store1] => abstract
[defaultswatch1] =>
[swatch1] =>
[store0] => abstract
[defaultswatch0] =>
[swatch0] =>
)

[828] => Array
(
[checked] =>
[intype] => radio
[id] => 1382
[sort_order] => 829
[store1] => caol color
[defaultswatch1] =>
[swatch1] =>
[store0] => caol color
[defaultswatch0] =>
[swatch0] =>
)

[829] => Array
(
[checked] =>
[intype] => radio
[id] => 1381
[sort_order] => 829
[store1] => cool color
[defaultswatch1] =>
[swatch1] =>
[store0] => cool color
[defaultswatch0] =>
[swatch0] =>
)









share|improve this question














I am having the array of color attribute options...



I would like to sort the array based on 'store0' key...



I have used multisort and usort but its not working



[821] => Array
(
[checked] =>
[intype] => radio
[id] => 969
[sort_order] => 513
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow - KID
[defaultswatch0] =>
[swatch0] =>
)

[822] => Array
(
[checked] =>
[intype] => radio
[id] => 207
[sort_order] => 309
[store1] => Yellow Beige - Chroma 1 ½
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow Beige - Chroma 1 ½
[defaultswatch0] =>
[swatch0] =>
)

[823] => Array
(
[checked] =>
[intype] => radio
[id] => 857
[sort_order] => 403
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-RAIN HAT BOB
[defaultswatch0] =>
[swatch0] =>
)

[824] => Array
(
[checked] =>
[intype] => radio
[id] => 860
[sort_order] => 406
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN
[defaultswatch0] =>
[swatch0] =>
)

[825] => Array
(
[checked] =>
[intype] => radio
[id] => 851
[sort_order] => 400
[store1] => Yellow
[defaultswatch1] =>
[swatch1] =>
[store0] => Yellow-WOMEN1
[defaultswatch0] =>
[swatch0] =>
)

[826] => Array
(
[checked] =>
[intype] => radio
[id] => 29
[sort_order] => 310
[store1] => Zebra
[defaultswatch1] =>
[swatch1] =>
[store0] => Zebra
[defaultswatch0] =>
[swatch0] =>
)

[827] => Array
(
[checked] =>
[intype] => radio
[id] => 1383
[sort_order] => 830
[store1] => abstract
[defaultswatch1] =>
[swatch1] =>
[store0] => abstract
[defaultswatch0] =>
[swatch0] =>
)

[828] => Array
(
[checked] =>
[intype] => radio
[id] => 1382
[sort_order] => 829
[store1] => caol color
[defaultswatch1] =>
[swatch1] =>
[store0] => caol color
[defaultswatch0] =>
[swatch0] =>
)

[829] => Array
(
[checked] =>
[intype] => radio
[id] => 1381
[sort_order] => 829
[store1] => cool color
[defaultswatch1] =>
[swatch1] =>
[store0] => cool color
[defaultswatch0] =>
[swatch0] =>
)






magento2.3.1 array sort






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 30 at 6:27









1990rk41990rk4

2039




2039












  • I know its a simple question .. but something went wrong...

    – 1990rk4
    May 30 at 6:28

















  • I know its a simple question .. but something went wrong...

    – 1990rk4
    May 30 at 6:28
















I know its a simple question .. but something went wrong...

– 1990rk4
May 30 at 6:28





I know its a simple question .. but something went wrong...

– 1990rk4
May 30 at 6:28










3 Answers
3






active

oldest

votes


















1














Here is the example, you can use this




function asc_sort (&$array, $key)
$sorter = array();
$ret = array();
reset($array);
foreach ($array as $ii => $va)
$sorter[$ii] = $va[$key];

asort($sorter);
foreach ($sorter as $ii => $va)
$ret[$ii] = $array[$ii];

$array = $ret;

asc_sort($a_array, "store0");






share|improve this answer






























    1














    $arr = your array from above;

    usort(
    $arr,
    function($a, $b)
    return strcmp($a['store0'], $b['store0']);

    );


    the usort function receives the first parameter by reference. So after the code above you can just iterate through $arr. It should be ordered by the store0 field.






    share|improve this answer






























      0














      $array = your_array;

      function compareOrder($x, $y)

      return $x['store0'] - $y['store0'];

      usort($array, 'compareOrder');





      share|improve this answer























        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "479"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276670%2fsorting-went-fail-for-array%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        Here is the example, you can use this




        function asc_sort (&$array, $key)
        $sorter = array();
        $ret = array();
        reset($array);
        foreach ($array as $ii => $va)
        $sorter[$ii] = $va[$key];

        asort($sorter);
        foreach ($sorter as $ii => $va)
        $ret[$ii] = $array[$ii];

        $array = $ret;

        asc_sort($a_array, "store0");






        share|improve this answer



























          1














          Here is the example, you can use this




          function asc_sort (&$array, $key)
          $sorter = array();
          $ret = array();
          reset($array);
          foreach ($array as $ii => $va)
          $sorter[$ii] = $va[$key];

          asort($sorter);
          foreach ($sorter as $ii => $va)
          $ret[$ii] = $array[$ii];

          $array = $ret;

          asc_sort($a_array, "store0");






          share|improve this answer

























            1












            1








            1







            Here is the example, you can use this




            function asc_sort (&$array, $key)
            $sorter = array();
            $ret = array();
            reset($array);
            foreach ($array as $ii => $va)
            $sorter[$ii] = $va[$key];

            asort($sorter);
            foreach ($sorter as $ii => $va)
            $ret[$ii] = $array[$ii];

            $array = $ret;

            asc_sort($a_array, "store0");






            share|improve this answer













            Here is the example, you can use this




            function asc_sort (&$array, $key)
            $sorter = array();
            $ret = array();
            reset($array);
            foreach ($array as $ii => $va)
            $sorter[$ii] = $va[$key];

            asort($sorter);
            foreach ($sorter as $ii => $va)
            $ret[$ii] = $array[$ii];

            $array = $ret;

            asc_sort($a_array, "store0");







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 30 at 6:43









            Sohel RanaSohel Rana

            24.3k34664




            24.3k34664























                1














                $arr = your array from above;

                usort(
                $arr,
                function($a, $b)
                return strcmp($a['store0'], $b['store0']);

                );


                the usort function receives the first parameter by reference. So after the code above you can just iterate through $arr. It should be ordered by the store0 field.






                share|improve this answer



























                  1














                  $arr = your array from above;

                  usort(
                  $arr,
                  function($a, $b)
                  return strcmp($a['store0'], $b['store0']);

                  );


                  the usort function receives the first parameter by reference. So after the code above you can just iterate through $arr. It should be ordered by the store0 field.






                  share|improve this answer

























                    1












                    1








                    1







                    $arr = your array from above;

                    usort(
                    $arr,
                    function($a, $b)
                    return strcmp($a['store0'], $b['store0']);

                    );


                    the usort function receives the first parameter by reference. So after the code above you can just iterate through $arr. It should be ordered by the store0 field.






                    share|improve this answer













                    $arr = your array from above;

                    usort(
                    $arr,
                    function($a, $b)
                    return strcmp($a['store0'], $b['store0']);

                    );


                    the usort function receives the first parameter by reference. So after the code above you can just iterate through $arr. It should be ordered by the store0 field.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 30 at 6:41









                    MariusMarius

                    169k28329702




                    169k28329702





















                        0














                        $array = your_array;

                        function compareOrder($x, $y)

                        return $x['store0'] - $y['store0'];

                        usort($array, 'compareOrder');





                        share|improve this answer



























                          0














                          $array = your_array;

                          function compareOrder($x, $y)

                          return $x['store0'] - $y['store0'];

                          usort($array, 'compareOrder');





                          share|improve this answer

























                            0












                            0








                            0







                            $array = your_array;

                            function compareOrder($x, $y)

                            return $x['store0'] - $y['store0'];

                            usort($array, 'compareOrder');





                            share|improve this answer













                            $array = your_array;

                            function compareOrder($x, $y)

                            return $x['store0'] - $y['store0'];

                            usort($array, 'compareOrder');






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 30 at 6:59









                            Saphal JhaSaphal Jha

                            1,257717




                            1,257717



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Magento Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276670%2fsorting-went-fail-for-array%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                                Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                                Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림