duan7664 2013-12-05 16:17
浏览 24
已采纳

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!!

  • 写回答

3条回答 默认 最新

  • dtxa49711 2013-12-05 17:30
    关注

    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>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?