last day (15 days later) » 

8:40 PM
0
A: Sorting array using template

Clément MaletYou should use array_keys instead of array_search and send the key of the current $point you are treating to your callback : $routes = [['A','B','C','D'],['A','C','E','F'],['D','O','A','F']]; $points = [['C','A','A','B','C','C'], ['E','E','C','A'],['F','O','O','A','A']]; foreach ($points as $key =

 
Thank you for the reply, but the code is not yet ok.. It does not order the results as wanted..
 
@rosuandreimihai Uh, then you may have to add some details on the output you expect. Don't you want to orders points with the corresponding route ?
 
Yes, but the result given to me looks different then yours: [['C','A','A','B','C','C'], ['E','E','C','A'],['F','O','O','A','A']]
 
@rosuandreimihai Did you copy the exact same code as me ? Including the reference (&) on the $point variable ? Otherwise it's not sorting anything. That's why you would have an unchanged result.
 
I just pasted your code to phptester.net, and the result differs..
 
8:40 PM
@rosuandreimihai The result is the same on phptester, check PHP 5.4 instead of the default PHP 5.3 value.
 
So, if I have PHP 5.3 this code will not help me.., any ideea on how to convert it to php 5.3?
 
@rosuandreimihai Of course, use array() instead of [] to init your arrays: array(array('A','B','C','D'),array('A','C','E','F'),array('D','O','A','F'));
 
actually, in my live system
where i want to use this code, i have only arrays
and still doesn't work
sorry for the intrusion
 
Hum
The solution with array(...)
Instead of [ ... ]
Should work
No matter which version of PHP you are running
 
yes, but when filling the arrays, I have this statment
$routes[$key][] = $_route->get_route_points();
$routes is declared as array()
 
8:43 PM
I don't see why it would not work though
It's an ok way to init the array
And it has nothing to do with the sort
Maybe your $points and $routes do not have the same keys ?
 
"routes":[[["Targoviste","Ploiesti","Buzau","Bacau","Roman"]]],"points":[["Roman‌​","Targoviste","Buzau","Bacau","Buzau"]]
this is the real json that I catch after your code
 
Hum
Your routes has a depth of 3
And not 2 like points
Try this maybe :
 
that could be the reason?
 
return array_keys($routes[$key][0], $a) > array_keys($routes[$key][0], $b);
Or
return array_keys($routes[0][$key], $a) > array_keys($routes[0][$key], $b);
Not sure which one
Yeah that would definitly be the reason ^^
 
thank you!
 
8:47 PM
My code assumed that both arrays have the same depth
 
it worked perfect using the [0]
 
It worked ?
Glad :)
 
yes, it was obvious the mistake done
 
Feel free to upvote me if I helped ^^
 
thank you for pointing me!
 
8:47 PM
Glad you're done with it
 
sure, right now
 

last day (15 days later) »