|
Posted by christiang on 02/07/06 22:10
Actually, I tried the sorting outside my class and it works properly:
$arr = array();
$arr['del.icio.us'] = array( "relationCount_int" => 1, "name_str" =>
"del.icio.us");
$arr['php'] = array( "relationCount_int" => 1, "name_str" => "php");
$arr['framework'] = array( "relationCount_int" => 2, "name_str" =>
"framework");
$arr['javascript'] = array( "relationCount_int" => 3, "name_str" =>
"javascript");
$arr['google'] = array( "relationCount_int" => 1, "name_str" =>
"google");
$arr['xml'] = array( "relationCount_int" => 1, "name_str" => "xml");
$arr['RIA'] = array( "relationCount_int" => 1, "name_str" => "RIA");
$arr['library'] = array( "relationCount_int" => 1, "name_str" =>
"library");
$arr['design'] = array( "relationCount_int" => 1, "name_str" =>
"design");
$arr['development'] = array( "relationCount_int" => 2, "name_str" =>
"development");
$arr['webdesign'] = array( "relationCount_int" => 1, "name_str" =>
"webdesign");
$arr['web'] = array( "relationCount_int" => 1, "name_str" => "web");
function cmp($a, $b)
{
//print_r($a['relationCount_int']." ==
".$b['relationCount_int']."<br>");
if ($a['relationCount_int'] == $b['relationCount_int']) {
return 0;
}
return ($a['relationCount_int'] > $b['relationCount_int']) ? -1 : 1;
}
usort($arr, "cmp");
print "<pre>";
print_r($arr);
print "</pre>";
I have problem on modifying the array of my class, I tried even to
remove the elements but I can't:
foreach($this->relatedtags_arr as $relatedtag){
unset($this->relatedtags_arr[$relatedtag['name_str']]);
}
Although the count() becomes 0, the elements are still there. How could
modify that array, and how could I do inside my class? Any idea? Thanks
a lot, chr
Navigation:
[Reply to this message]
|