usort Questions
5
Solved
I'm trying to do the same as MySQL query
SELECT * FROM table ORDER BY field1, field2, ...
but with php and a multidimensional array:
$Test = array(
array("a"=>"004", "n"=>"03"),
array("a...
Twigg asked 2/4, 2014 at 13:13
6
Solved
What I'm trying to do is sort a multi-dimensional array that contains decimal values. From what I've tested, floats are having trouble being ordered properly.
Array
(
[0] => Array
(
[company...
Beitris asked 11/4, 2013 at 5:6
3
Solved
The following code lays within a function which itself lays within a class. Its purpose is to avoid having one sorting function per $filter value :
$GLOBAL['filter'] = $filter;
usort($this->dat...
6
Solved
I have the following functions. WordPress functions, but this is really a PHP question. They sort my $term objects according to the artist_lastname property in each object's metadata.
I want ...
3
Solved
This is a sample of the array of elemnts to sort:
$items =
array
0 =>
object(stdClass)[8]
public 'id' => string '110' (length=3)
public 'brand_id' => string '18' (length=2)
array
...
3
Solved
the code
<?php
$consts = get_defined_constants();
$consts = array_keys($consts);
usort($consts,function($a,$b){return (int)(strlen($a)<strlen($b));});
foreach($consts as $const){
echo strlen...
3
Solved
I have a problem with usort not liking the second parameter (the sorting function). I have seen a lot of questions about this being a problem when in a class, and the answer for that is to pass an ...
2
Solved
I'm trying to take a string in the format of mdY H:i and sort it in an array. My code for the sort is:
function orderDates($items) {
//Sort them. Latest one first
usort($items, function ($a, $b)...
3
Solved
I have an array of filenames of this form:
"A - 1.2 - Floor Plan.PDF"
I need to sort the array first by the category at the beginning, in the following order:
1. Category: A
2. Category: ESC
3....
4
Solved
I have array that I need to sort by another array form 2 fields zip code and approve
I am able to sort it by zip code but unable to do it with approved field so for eg
I need to sort by 60007,600...
Flews asked 1/9, 2014 at 10:1
5
Solved
When I try to apply the below code from here
usort($myArray, function($a, $b) {
return $a['order'] - $b['order'];
});
it gives me results in ascending order.
Output:
0
0
0
0
0
0.29
1.09
6.3...
Gabrielson asked 26/1, 2013 at 6:57
4
Solved
I am currently creating a sorting method that consists of values from an mysql query.
Here's a brief view of the array:
Array
(
[0] => Array
(
['id'] = 1;
['countries'] = 'EN,CH,SP';
)
...
Presnell asked 13/1, 2010 at 18:37
1
Solved
Is there a more compact way to sort an array by two parameters/fields with PHP ≥7.0 (using the spaceship operator <=>) ?
Right now I just to the trick to sort is first by the second par...
2
Solved
I have an array sorting function as follows:
public function sortAscending($accounts)
{
function ascending($accountA, $accountB) {
if ($accountA['AmountUntilNextTarget'] == $accountB['AmountUnti...
1
Solved
I have 2 arrays.
Array1 looks something like this (which is just a small example, in reality it haves more then 408 rows):
Array
(
[0] => Array ( [536870925] => 34213897 )
[1] => ...
3
Solved
I am having MAJOR usort() issues! :( So basically I want to sort my array by their values. I would like the values to display in this order: Platinum, Gold, Silver, Bronze, Complete, None, Un...
3
Solved
I have a usort function with a single line: return 0.
I tried to use it on an Array of stdClass objects, and it changes
their order, how is that possible?
7
Solved
I have an array like the following:
Array
(
[0] => Array
(
'name' => "Friday"
'weight' => 6
)
[1] => Array
(
'name' => "Monday"
'weight' => 2
)
)
I would like to grab the last v...
Panocha asked 13/9, 2010 at 15:27
4
Solved
I'm rewriting an old script that spits out the most popular content using usort.
For some reason, the output of my usort isn't actually sorted.
I'm using php 5.5 (please disregard the use of the...
1
Solved
I need to sort the following array with following logic: If the 'score' is the same, I want to compare using 'time'. The array is as follows:
$user_scores = [ 82 => [ 'score' => 1, 'time' =&...
Clorindaclorinde asked 1/6, 2017 at 13:58
3
Solved
This is a really esoteric question, but I'm genuinely curious. I'm using usort for the first time today in years, and I'm particularly interested in what exactly is going on. Suppose I've got the f...
2
Solved
There's an answer here: Combine two array and order this new array by date
It explains how two arrays can be merged and then sorted by date.
function cmp($a, $b){
$ad = strtotime($a['date']);
$...
1
I have multidimensional array that i want to sort by field containing unix timestamp:
Array (
[0] => Array ( [0] => 723 [1] => 1442008738 )
[1] => Array ( [0] => 721 [1] =&...
2
Solved
If have a rather basic uasort function in PHP that looks like this:
uasort($arr, function($a, $b) {
if ($a > $b)
return -1;
if ($a < $b)
return 1;
...
}
The array I'm trying to sort lo...
5
Solved
I have looked at the php documentation, tutorials online and none of them how usort is actually working. I have an example i was playing with below.
$data = array(
array('msg' => 'some text',...
Holiday asked 10/12, 2011 at 11:0
1 Next >
© 2022 - 2024 — McMap. All rights reserved.