in_array不起作用,它应该是[关闭]

Alright, i've tried everything. SO is my last resort!!

heres my code:

for($i = 0; $i < 15; $i++){
    $coach = $trainergross[$i]['instr'];
    $tclub = $trainergross[$i]['club'];
    $rookcheck = "$coach $tclub";
    if(in_array(trim(strtolower($rookcheck)), $rook)){
    $pls = 'y no work';
    }
    echo "$rookcheck $pls <br>";
}

here is print_r($rook):

Array ( [0] => jess p )

and here is what echo "$rookcheck $pls <br>"; is creating

naps d
sarah c
richie e
lee b
kate e
jess p <---- WHY ISNT THIS ECHOING $PLS???
josh d
chris e

if i use in_array('jess p', $rook) it works. so is the loop breaking this? i dont know. i'm getting mad!

Thanks for your help!!

This should work for you

$trainergross = array(
        array(
                'instr' => 'naps',
                'club' => 'd',
        ),
        array(
                'instr' => 'sarah',
                'club' => 'c',
        ),
        array(
                'instr' => 'richie',
                'club' => 'e',
        ),
        array(
                'instr' => 'lee',
                'club' => 'b',
        ),
        array(
                'instr' => 'kate',
                'club' => 'e',
        ),
        array(
                'instr' => 'jess',
                'club' => 'p',
        ),
        array(
                'instr' => 'josh',
                'club' => 'd',
        ),
        array(
                'instr' => 'chris',
                'club' => 'e',
        ),
);
$rook[] = "chris e";

for($i = 0; $i < count($trainergross); $i++){
    $coach = $trainergross[$i]['instr'];
    $tclub = $trainergross[$i]['club'];
    $rookcheck = $coach.' '.$tclub;

    if(in_array(trim(strtolower($rookcheck)), $rook)){
        $pls = 'y no work';
    }
    echo $rookcheck.$pls."<br>";
}

I had to 'reverse engineer' your $trainergross array & I think it looks something like this:

array(
  array(
    'instr' => 'naps',
    'club' => 'd',
  ), 
  array(
    'instr' => 'sarah',
    'club' => 'c',
  ),
  array(
    'instr' => 'richie',
    'club' => 'e',
  ),
  array(
    'instr' => 'lee',
    'club' => 'b',
  ),
  array(
    'instr' => 'kate',
    'club' => 'e',
  ),
  array(
    'instr' => 'jess',
    'club' => 'p',
  ),
  array(
    'instr' => 'josh',
    'club' => 'd',
  ),
  array(
    'instr' => 'chris',
    'club' => 'e',
  ),
);

With this array, your code mostly works. As Wayne Whitty suggested, please use the extra line to set & reset $pls in the loop. Also, because your array doesn't have 15 items, this 15 × for loop will cause errors. You might want to look at the foreach construct.

I think it would be most beneficial to present a debugging technique rather than provide the actual answer:

for($i = 0; $i < 15; $i++){
    $coach = $trainergross[$i]['instr'];
    $tclub = $trainergross[$i]['club'];
    $rookcheck = "$coach $tclub";

    // echo your actual IF statement and see if it makes sense
    echo "if(in_array(".trim(strtolower($rookcheck)).", ".print_r($rook, true).")){";

    if(in_array(trim(strtolower($rookcheck)), $rook)){

        // echo something for the heck of it
        echo 'We\'re in!<br>';

        $pls = 'y no work';
    }

    echo "$rookcheck $pls <br>";
}