Mailinglisten-Archive |
Hallo Michael,
> also ich hab ei array ala:
>
> Array[0][name] => AnaLogiC
> Array[0][id] => 46080
> Array[0][time] => 1097432914
> Array[0][status] => 1
>
> Array[1][name] => Smirrel
> Array[1][id] => 44539
> Array[1][time] => 1097432872
> Array[1][status] => 1
>
> Array[2][name] => athi
> Array[2][id] => 4584
> Array[2][time] => 1097432872
> Array[2][status] => 1
>
> Usw...
>
> So, jetz will ich zun einen das array so sortieren das es nach [name]
> sortiert wird, aber gross und klein schreibung egal sind, also das alle a's
> zu erst kommen
So löse ich das:
-----<snip>-----
function sort_multidim_array($unsort_array, $colum_to_sort)
/*
* This function sorts a multidimensional array of the sort:
* array(array(1, 2, 3, 4)
* array(3, 5, 6, 8))
*
* It takes an array and the colum number ($colum_to_sort) the array
should be
* sorted.
*/
{
for($k = 0; $k < sizeof($unsort_array) -1; $k++)
{
// $unsort_array[$k+1] is possibly in the wrong place. Take
it out.
$array_sort_part = $unsort_array[$k+1];
$i = $k;
// Push $unsort_array[i] to the right until we find the right
place for $t.
while($i >= 0 &&
strip_tags(strtolower($unsort_array[$i][$colum_to_sort])) >
strip_tags(strtolower($array_sort_part[$colum_to_sort])))
//Change sorting by changing the second < or > in the upper row.
{
$unsort_array[$i+1] = $unsort_array[$i];
$i--;
}
// Insert $t into the right place.
$unsort_array[$i+1] =
$array_sort_part;
}
/*
* In the next Section the sorted array is devided in one part with
* low quality data, eg. "", "-" or "- -" and one with good quality
data.
* The good quality comes first, then the low quality is appended.
*/
array($array_part_to_sort);
array($array_part_to_sort_not);
$counter_to_sort = 0;
$counter_to_sort_not = 0;
for($counter = 0; $counter < sizeof($unsort_array); $counter++)
{
if(strip_tags($unsort_array[$counter][$colum_to_sort]) == "" ||
strip_tags($unsort_array[$counter][$colum_to_sort]) == "-" ||
strip_tags($unsort_array[$counter][$colum_to_sort]) == "- -")
{
$array_part_to_sort[] = $unsort_array[$counter];
$counter_to_sort++;
}
else
{
$array_part_to_sort_not[] = $unsort_array[$counter];
$counter_to_sort++;
}
}
$ready_array = array_merge($array_part_to_sort_not,
$array_part_to_sort);
return $ready_array;
}
-----</snip>-----
> Zum zweiten will ich aus dem array ein hauptelement anhand der [id] aus dem
> array löschen.
Siehe der zweite Teil der function, so auf die Art und Weise kannst du
das löschen.
> Irgentwie brachte mich die php doku nich weiter...
Ging mir vor 3 Wochen auch so :-)
Grüssle, Tobias
php::bar PHP Wiki - Listenarchive