I’m working on a php issue with an associative array and attempting to sort it. What I have looks something like this: I want to sort it so it looks like this: I’ve thought about exploding along the | and then taking the 0.0.0.111 and comparing it to everything else. What I tried look like this: I realized though that
Tag: sorting
Array sort by key where keys are clothes sizes (S, M, L, etc.)
I have an array where it’s keys are the sizes and values are either ‘in-stock’ or ‘no-stock’. Example array: I’m trying to sort this by size. Expected output is: I’ve been looking at other similar questions but with no success because those had different array structures. I’m struggling with the uksort function since what I want is to sort the
Natural array sorting with proper decimal support in PHP
I want to sort an array with numbers in natural order, so numbers with a bigger value come after smaller ones like this: This is what I get as result, which is not the result I need, decimals are not threated correctly. There is already a similar question Array Sorting in php for decimal values but no fitting answer was
PHP topological sort
LIST: controller name => priority:required controllers sorted and expected output: First sort by priority, then reorder based on required controllers to be loaded before. ensure not to be stuck in an infinite loop due to controllers requiring each other. I assume I’ll need something like this: Please help solve this with these steps: Remove infinite loop controllers (ex: controller_loopexit1 &
Sort an array so that a given value would be the first
I would like to sort the array so that if a given value ($first_in_array) = ‘brand’ value, the array would become the first it the queue. In the given example an array with index[1] should appear like at index[0]. Answer You can use the callback function of usort and first deal with the case where exactly one of the two
PHP array_multisort with array_column not working
I am trying to sort multidimensional arrays by a single column. I have an array that is created in a method and returned as $GDdata. This is a snippet of my unsorted array displayed in a table. Here I am selecting the column I want the final array to be sorted by: $GDcol = array_column($GDdata,0); I can successfully print the
How to sort an Array using If in PHP
I have the following Array which contains data such as: Card, Month and Year. However, I receive it in a disorganized way and I would like to treat these values to follow the pattern. No Card, Year and Month or Month, Card and Year. I tried to use the sort() functions of php, but without success! I would like to
How to sort a 2-D array by the values of any specific key in PHP alphabetically?
I’ve got a multidimensional array that I want to sort alphabetically by the values of specific key. Structure of the array is – I wanted to sort the data on basis of key ‘deptt’ alphabetically by the values. My desired output should be like all ‘GTT-HOTELS’ data should shown first then ‘KKT-HOTELS’ – Any ideas how to do this? Hope
How can I sort an array stating in a given number
First of all I am new in php. I need help to sort an array. I have an array of ID’s and zip codes like this: Now I have a number lets say ‘2900’ I would like to sort my array from the closest number (2900) to the most distant. Example: the number is 2900. So the array should sort
Laravel get most recent array item for each day in array
I’m trying to figure out the best way (whether I do this using the query builder or raw PHP) to get the most recent array item based on it’s created_at timestamp for a given day, in an array …