-2

I have a table like below :
enter image description here

and using below way to calculate result as array

while($Br_ROWS = mysql_fetch_assoc($Bracket_Query)){
     $Bracket_Result[] = $Br_ROWS;
}

Array result like below :

Array
(
    [0] => Array
        (
            [Guid] => 1
            [Tournament] => 1
            [Position] => A1-1
            [Player] => 123
            [Team] => 
        )

    [1] => Array
        (
            [Guid] => 2
            [Tournament] => 1
            [Position] => A2-1
            [Player] => 325
            [Team] => 
        )

    [2] => Array
        (
            [Guid] => 3
            [Tournament] => 1
            [Position] => B2-1
            [Player] => 325
            [Team] => 
        )

    [3] => Array
        (
            [Guid] => 4
            [Tournament] => 1
            [Position] => A1-2
            [Player] => 235
            [Team] => 
        )

)

I Try but don't know how to do it .
How to specify value of Player when Position is A2-1 (for example)
I'm using a wrong way ?

4

1 回答 1

1

简单地用foreach

foreach ($Bracket_Result as $row)
{
   if ($row['Position'] == "A1-2") {
      echo "I found you:".$row['Player'];
   }
}

或者您可以创建一个返回播放器的函数:

function getPlayerbyPosition($players, $position)
{
    foreach ($players as $player)
    {
       if ($player['Position'] == $position) {
          return $player;
       }
    }
}

$result = getPlayerbyPosition($Bracket_Result, "A1-2");
var_dump($result);
于 2013-08-19T09:11:04.507 回答