Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good evening my helpers! I have a multidimensional array $data like this:
PHP
Array
(
[0] => thunderteszt
[1] => orevikod
[2] => 5400
[3] => 6
)
Array
(
[0] => bakterhaz1982
[1] => $s$w$0ffТΉЏИÐΞЯ
[2] => 5540
[3] => 3
)
Array
(
[0] => bakterhaz1982
[1] => $s$w$0ffТΉЏИÐΞЯ
[2] => 5570
[3] => 2
)
Array
(
[0] => bakterhaz1982
[1] => $s$w$0ffТΉЏИÐΞЯ
[2] => 5740
[3] => 1
)
Array
(
[0] => thunderteszt
[1] => orevikod
[2] => 5840
[3] => 5
)
Array
(
[0] => thunderteszt
[1] => orevikod
[2] => 5890
[3] => 4
)


You can see I have arrays with repeated nick in row[1] ($s$w$0ffТΉЏИÐΞЯ). I will pick up the lowest value (row[2]) from the repeated arrays.

Therafter I will make a new array from the picked values and I will see only the following:

Array
(
[0] => thunderteszt
[1] => orevikod
[2] => 5400
[3] => 6
)
Array
(
[0] => bakterhaz1982
[1] => $s$w$0ffТΉЏИÐΞЯ
[2] => 5540
[3] => 3
)


What I have tried:

function pts_panel_on($aseco) {

global $pts;

$maniapos = -1;   
$linkmaniapos = -0.2;
$linkmaniapos2 = -0;
$xml = '<manialinks><manialink id="40400">';
$xml .= '<frame posn="48.2 15 0">';
if (empty($pts->finish)) return true;

$beerok=array();

foreach($pts->finish as $key=>$row){   
$becenev[$key] = $row['nick'];  
$ido[$key] = $row['score']; 
} 

array_multisort($ido, SORT_ASC, $becenev, SORT_ASC, $pts->finish );
foreach($pts->finish as $data){
print_r(array_values($data));
$rpointinc++;
$linkmaniapos =  ($linkmaniapos - 3) ;
$linkmaniapos2 =  ($linkmaniapos2 - 3) ;
$maniapos =  ($maniapos - 3) ;

if ($rpointinc <= 10) { 

$xml .= '<format textsize="1"/><label posn="-19.3 ' . $linkmaniapos. ' 
1.5" sizen="30 3 2" scale="0.3" style="TextRaceChrono" halign="center" 
text="$s$0f0'.$rpointinc .' "/>';
$xml .= '<format textsize="1"/><label posn="-27.5 ' . $linkmaniapos . ' 1.5" 
sizen="30 3 2" halign="left" scale="0.3" style="TextRaceChrono" 
text="$s$fff'.formatTime($data['score']).' "/>';   
$xml .= '<format textsize="1.7"/><label posn="-16.5 ' . $linkmaniapos . ' 
1.6" sizen="12 3 2" halign="left" text="$000' . $data['nick'] . ' "/>';

$xml .= '<quad sizen="4 3" posn="-19.6 ' . $maniapos . ' 1"  valign="center" 
halign="center" style="Bgs1InRace" substyle="NavButton" />';
$xml .= '<quad sizen="6.2 3" posn="-24.9 ' . $maniapos . ' 1"  
valign="center" halign="center" style="Bgs1InRace" substyle="NavButton" />';
$xml .= '<quad sizen="17 3" posn="-17.4 ' . $maniapos . ' 1.1"  
valign="center" halign="left" style="Bgs1InRace" substyle="NavButton"/>';
}

}
$xml .= '</frame>';
$xml .= '</manialink></manialinks>';
foreach ($pts->Players as $data2) {
$aseco->client->query("SendDisplayManialinkPageToLogin", $data2['login'], 
$xml, 0, false);
}
}
Posted
Updated 24-Apr-18 3:39am
Comments
Kornfeld Eliyahu Peter 22-Apr-18 15:19pm    
The original data structure is given, or it is up to you?
Member 13792515 23-Apr-18 8:40am    
This code for online game. When the player reach finish, i got his login, nick, score, and position. But when he finish 5 times in a row, then i have 5 arrays with his details. I will keep just one, where he have the lowest score

1 solution

 
Share this answer
 
Comments
Member 13792515 24-Apr-18 14:09pm    
is not 100% like I want.
I will try explain with another way what I want.
The basic array multidimensional, like this:
Array(
Array
(
[0] => a
[1] => 33
)
Array
(
[0] => b
[1] => 26
)
Array
(
[0] => a
[1] => 11
)
Array
(
[0] => c
[1] => 22
)
)
When I foreach this array, I have 2 arrays with same name "a" but different values "33" and "11".
I will keep only the smallest value and drop/delete the bigest one.
So my final array will see like this:
Array(
Array
(
[0] => b
[1] => 26
)
Array
(
[0] => a
[1] => 11
)
Array
(
[0] => c
[1] => 22
)
)
Member 13792515 24-Apr-18 16:44pm    
now i got this messages:
[PHP Warning] min(): When only one parameter is given, it must be an array on line 317 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] max(): When only one parameter is given, it must be an array on line 318 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] min(): When only one parameter is given, it must be an array on line 317 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] max(): When only one parameter is given, it must be an array on line 318 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] min(): When only one parameter is given, it must be an array on line 317 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] max(): When only one parameter is given, it must be an array on line 318 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] min(): When only one parameter is given, it must be an array on line 317 in file /home/xaseco/plugins/plugin.goalrace.php
[PHP Warning] max(): When only one parameter is given, it must be an array on line 318 in file /home/xaseco/plugins/plugin.goalrace.php
Array
(
[0] => Array
(
[0] => Array
(
[login] => thunderteszt
[nick] => orevikod
[score] => 5660
[pos] => 4
)

[1] => Array
(
[login] => bakterhaz1982
[nick] => $s$w$0ffТΉЏИÐΞЯ
[score] => 5770
[pos] => 1
)

[2] => Array
(
[login] => thunderteszt
[nick] => orevikod
[score] => 6080
[pos] => 3
)

[3] => Array
(
[login] => bakterhaz1982
[nick] => $s$w$0ffТΉЏИÐΞЯ
[score] => 6250
[pos] => 2
)

)

)

my code now:

function pts_panel_on($aseco) {

global $pts;

$maniapos = -1;
$linkmaniapos = -0.2;
$linkmaniapos2 = -0;
$xml = '<manialinks><manialink id="40400">';
$xml .= '';
if (empty($pts->finish)) return true;

$beerok=array();

foreach($pts->finish as $key=>$row){
$becenev[$key] = $row['nick'];
$ido[$key] = $row['score'];
}

array_multisort($ido, SORT_ASC, $becenev, SORT_ASC, $pts->finish );


$templevel=0;

$newkey=0;
$grouparr = array ();
$grouparr[$templevel]="";

foreach ($pts->finish as $key => $val) {
if ($templevel==$val[login]){
$grouparr[$templevel][$newkey]=$val;
} else {
$grouparr[$val[login]][$newkey]=$val;
}
$newkey++;
print_r ($grouparr[login]);
print_r (min($grouparr[score]));
print_r (max($grouparr[score]));
}
print_r($grouparr);
...
Member 13792515 24-Apr-18 16:45pm    
i think i must give up this, because too complicated :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900