Good day, tell me how for example to count the number of "programs" for player_name 106.

[list_match_timeline] => stdClass Object ( [type] => Array ( [0] => передача [1] => взятие_ворот [2] => удаление_2_мин [3] => командный_штраф [4] => удаление_2_мин [5] => взятие_ворот [6] => удаление_2_мин [7] => взятие_ворот [8] => передача [9] => взятие_ворот [10] => конец_первого_периода [11] => удаление_2_мин [12] => взятие_ворот [13] => передача [14] => взятие_ворот [15] => взятие_ворот [16] => взятие_ворот [17] => передача [18] => взятие_ворот [19] => передача [20] => взятие_ворот [21] => конец_второго_периода [22] => удаление_2_мин [23] => передача [24] => взятие_ворот [25] => передача [26] => взятие_ворот [27] => передача [28] => взятие_ворот [29] => передача [30] => взятие_ворот [31] => конец_третьего_периода ) [player] => Array ( [0] => 106 [1] => 118 [2] => 171 [3] => 1 [4] => 169 [5] => 176 [6] => 122 [7] => 117 [8] => 106 [9] => 174 [10] => 1 [11] => 124 [12] => 118 [13] => 124 [14] => 122 [15] => 154 [16] => 118 [17] => 106 [18] => 122 [19] => 106 [20] => 122 [21] => 1 [22] => 124 [23] => 176 [24] => 174 [25] => 117 [26] => 118 [27] => 114 [28] => 115 [29] => 118 [30] => 114 [31] => 1 ) ) 

    2 answers 2

    You have 2 arrays in the stdClass object.

    As I understood from their structure, for example, player_name indexes, for example, 106 correspond to transmission indexes.

    To calculate the number of gears for 106 numbers I can offer the following algorithm:

     $types = list_match_timeline->type; //first array $players = list_match_timeline->player //second array $allTypesForOnePlayer = []; $countallTypesForOnePlayer = 0; foreach ($players as $key => $player) { if ($value == 106) { $allTypesForOnePlayer[] = $types[$key]; $countallTypesForOnePlayer++; } } var_dump($allTypesForOnePlayer); //список всех передач для пользователя 106 echo $countallTypesForOnePlayer; // ко-во передач для 106 
    • The code is not quite true. It counts all matches with 106, and not just “transmissions” - IntegratorPB

    Solved the problem differently. Collected a new array from two and recalculated the necessary values.

     $match_timeline_types = $stats->list_match_timeline->type; $match_timeline_players = $stats->list_match_timeline->player; //Собираем массив $timeline_key = 0; // Match timeline $stats->match_timelines = array(); foreach ($match_timeline_types as $key => $match_timeline_type) { // Timelines $stats->match_timelines[$timeline_key] = array( 'type' => $match_timeline_types[$key], 'player' => $match_timeline_players[$key], ); $timeline_key ++; $pass =0; foreach($stats->match_timelines as $timeline){ if($timeline['player'] == $this->item->spsoccer_player_id && $timeline['type'] == 'передача'){ $pass++; } } 

    Thank.