Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

usort

Sort rows in a 2d array in a descending direction by comparing a column of float values [duplicate]

December 31, 2023 by Tarik
Categories php Tags arrays, multidimensional-array, php, sorting, usort Leave a comment

Keeping array index key when sorting a multidimensional array with PHP

August 12, 2023 by Tarik
Categories php Tags php, usort Leave a comment

How do I sort a PHP array by an element nested inside? [duplicate]

May 28, 2023 by Tarik

You can use usort as: function cmp($a, $b) { return $a[‘weight’] – $b[‘weight’]; } usort($arr,”cmp”);

Categories php Tags arrays, multidimensional-array, php, sorting, usort Leave a comment

usort(): Array was modified by the user comparison function

May 21, 2023 by Tarik

There is a PHP bug that can cause this warning, even if you don’t change the array. Short version, if any PHP debug functions examine the sort array, they will change the reference count and trick usort() into thinking you’ve changed the data. So you will get that warning by doing any of the following … Read more

Categories php Tags php, usort Leave a comment

Pass extra parameters to usort callback [duplicate]

May 14, 2023 by Tarik

I think this question deserves an update. I know the original question was for PHP version 5.2, but I came here looking for a solution and found one for newer versions of PHP and thought this might be useful for other people as well. For PHP 5.3 and up, you can use the ‘use‘ keyword … Read more

Categories php Tags callback, php, usort, wordpress Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa