cabrera48
asked on
usort() function producing bad results on a linux environment, ok on windows
This is really weird, the same code works on windows, but not on linux.
When I run the code below on a windows machine with PHP 5.2.5, it works perfect, I get the output array alphabetically ordered.
When I run it on a linux box running PHP 5.1.6 I get an array that doesn't have the same order as the original array, but it is also not properly sorted.
Do you guys know what part of my code is "environment dependant"? I can hardly believe the same code will produce two different results in different platforms...
When I run the code below on a windows machine with PHP 5.2.5, it works perfect, I get the output array alphabetically ordered.
When I run it on a linux box running PHP 5.1.6 I get an array that doesn't have the same order as the original array, but it is also not properly sorted.
Do you guys know what part of my code is "environment dependant"? I can hardly believe the same code will produce two different results in different platforms...
// The code here:
class TestTwo{
// This is just the contructor / driver:
function TestTwo(){
// bootstrapping the input array:
$sort_array = file_get_contents('test_array_sort.txt');
$attributes_array = unserialize($sort_array);
$this->attributes_array_sorted = $this->createAttributesArraySorted($attributes_array);
// At this point, I get the right output on Windows, and the badly sorted array in Linux
}
private function createAttributesArraySorted($attributes_array_){
foreach($attributes_array_ as &$val){
usort($val['children_nodes'], 'TestTwo::cpm_node');
}
return $attributes_array_;
} /* end private function createAttributesArraySorted($attributes_array_) */
/*
* Auxiliary function used to sort attributes in alphabetical order
*/
static function cpm_node($a,$b){
return strcasecmp($a['node_name'], $b['node_name']);
} /* end static function cpm_nodes() */
} /* end class TestTwo */
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are right, that was the problem, nothing to do with linux, but the PHP version I was using there.
Thank you.
Thank you.
Thanks for the question and the points.
ASKER
I put a print statement inside of it, and I can see the print output on windows, on linux it doesn't display.
So the problem seem to be in this line:
usort($val['children_nodes
Why would that fail to call TestTwo::cpm_node static function on linux?