PHP -Sortierfloat- und Ganzzahlwerte in Array - sort () [Duplikat]

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: PHP -Sortierfloat- und Ganzzahlwerte in Array - sort () [Duplikat]

by Guest » 16 Feb 2025, 11:11

Ich habe Probleme mit RSORT (). Ganzzahlen sind gleich, aber Float ist unterschiedlich. Mit einem Dezimalwert. < /p>
Hier ist mein Code: < /p>

Code: Select all

$a = 1.7;
$b = 1;
$c = 1.9;
$d = 1.4;
$num = [$a,$b,$c,$d];
rsort($num);

$high_name = [
$a => "a",
$b => "b",
$c => "c",
$d => "d",
];

$on1 = $high_name[$num[0]];
$on2 = $high_name[$num[1]];
$on3 = $high_name[$num[2]];
$on4 = $high_name[$num[3]];
Ich muss einen Buchstaben erhalten, der der höchsten Zahl im Array entspricht. stark> < /p>
Aber wenn ich es tue: < /p>

Code: Select all

echo "
on1 = $on1";
echo "
on2 = $on2";
echo "
on3 = $on3";
echo "
on4 = $on4";
< /code>
Ich erhalte: < /p>
on1 = d
on2 = d
on3 = d
on4 = d
< /code>
Ich muss wissen, wie die höchste Zahl im Array ist, sei es ganzzahlig oder float. < /p>
Das Ergebnis, nach dem ich suche: < /p>
on1 = c
on2 = a
on3 = d
on4 = b

Top