好吧,我已经尝试了一切。这是我最后的手段!!
继承我的代码:
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>";
}
这里是print_r($rook)
:
Array ( [0] => jess p )
以下是echo "$rookcheck $pls <br>";
创建的内容
naps d
sarah c
richie e
lee b
kate e
jess p <---- WHY ISNT THIS ECHOING $PLS???
josh d
chris e
如果我使用in_array('jess p', $rook)
它有效。这个循环打破了吗?我不知道。我生气了!
感谢您的帮助!!
答案 0 :(得分:1)
这应该对你有用
$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>";
}
答案 1 :(得分:0)
我必须'反向工程'你的$trainergross
阵列&amp;我觉得它看起来像这样:
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',
),
);
使用此数组,您的代码大多数都可以使用。正如Wayne Whitty建议的那样,请使用额外的线来设置&amp;在循环中重置$pls
。
此外,因为您的阵列没有15个项目,这个15×for循环将导致错误。您可能希望查看foreach构造。
答案 2 :(得分:0)
我认为提供调试技术而不是提供实际答案是最有益的:
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>";
}