-1

I have one array:

$logins= array("login1", "login2", "login3"I;

I have an event where all login (login1, login2, login3) have access.

Now login1,login2,login3 can click on event unlimited times.

I will reduce the access to the event maximum 2 times.

here is the code:

function replaychargeClick($aseco, $command) {
global $replaycharge, $replaybills;


$coppers = $replaycharge['coppers'];
$playerid = $command[0];
$login = $command[1];
$answer = $command[2].'';
$aseco->client->query('GetDetailedPlayerInfo', $login);
$player = $aseco->client->getResponse();
$nickname = $player['NickName'];
    if ($answer == '234561') {
    $aseco->client->query('GetCurrentChallengeInfo');
    $thistrack = $aseco->client->getResponse();
    $aseco->client->query('GetNextChallengeInfo');
    $nexttrack = $aseco->client->getResponse();

    // Check if already being replayed
    if ($thistrack['FileName'] != $nexttrack['FileName']) { 
        //  Check for TMF server
        if ($aseco->server->getGame() == 'TMF') {
            // check for TMUF server
            if ($aseco->server->rights) {
                // check for TMUF player
                if ($player['OnlineRights'] >= 0 ) {

                    // start the transaction
                    $message = 'You need to pay '.$coppers.' coppers to replay the track';
                    $aseco->client->query('SendBill', $login, $coppers, $message, '');
                    $replaybillid = $aseco->client->getResponse();
                    $replaybills[$replaybillid] = array($login, $nickname, $coppers);
                } else {
                $message = formatText($aseco->getChatMessage('UNITED_ONLY'), 'account');
                $aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
                }
            } else {
            $message = formatText($aseco->getChatMessage('UNITED_ONLY'), 'server');
            $aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
            }
        } else {
        $message = $aseco->getChatMessage('FOREVER_ONLY');
        $aseco->client->query('ChatSendServerMessageToLogin', $aseco->formatColors($message), $login);
        }
    } else {
    $message = '>$f00 This track is already being replayed';
    $aseco->client->query('ChatSendServerMessageToLogin', $message, $login);
    }
}

}

So how can I add a counter for each login?

1 Answer 1

0

If you want to store counter for all the logins, just add a key in the array.

$loginsWithCount = array({
  key: "login1,
  count: 0
}, {
  key: "login2,
  count: 0
}, {
  key: "login3,
  count: 0
});

Now, you can update the count by looping through the array and finding the right login object and updating its count or for optimization you can create a hash and do it.

$keyToUpdate = 'login1';
$countToUpdate = 10;

foreach ($array as $item) {
    if ($item->key === $keyToUpdate) {
        $item['count'] = $countToUpdate;
    }
}

Sign up to request clarification or add additional context in comments.

8 Comments

I'm not sure how can I do this.
Can You explain me how can I increase the count to 2 by "login2" ?
I'm really beginner in PHP :)
help me please :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.