Answer the question
In order to leave comments, you need to log in
If inside foreach?
I have this array
Array
(
[0] => Array
(
[ot_id] => 2
[ot_name] => Sisyukin Alexander Valerievich
[ot_email] => [email protected]
[ot_text] => pocoatsol acltsal tsla tsla tsll tsalts ltsl atsal ts
ts vts vtsv ts
[ot_kat] => 2
)
[1] => Array
(
[ot_id] => 1
[ot_name] => Nikishin Alexey Vasilievich
[ot_email] => [email protected]
[ot_text] => Revocation check plain text padding
[ot_kat] => 1
)
[2] =>Array
(
[kat_id] => 2
[kat_otz] => Bad review
)
[3] => Array
(
[kat_id] => 1
[kat_otz] => Good review
)
)
trying to display it like this
foreach ($res as $one)
{
echo $one['ot_name'] . '<br />';
echo $one['ot_text'] . '<br />';
if ($one['ot_kat'] == $one['kat_id'])
{
echo $one['kat_otz'] . '<br />';
} else
{
echo 'не работает';
}
}
Answer the question
In order to leave comments, you need to log in
Where is your kat_id key in the array?
What's with the fucking array anyway?
And if here and. As a construct, this is correct, but $one['ot_kat'] == $one['kat_id'].
Since you didn't specify what is in the $res variable, I can say that one of these: $one['ot_kat'], $one['kat_id'] will return null
$res_1 = array(
array(
'ot_id' => 1,
'ot_name' => 'Сисюкин Александр Валерьевич',
'ot_email' => '[email protected]',
'ot_text' => 'поцоацол ацлцал цла цла цлл цалц лцл ацал ц
ц вц вцв ц',
'ot_kat' => 1
)
);
$res_2 = array(
array(
'kat_id' => 1,
'kat_otz' => 'Хороший отзыв'
)
);
foreach( $res_1 as $val_1 ){
foreach( $res_2 as $val_2 ){
if( $val_1['ot_kat'] == $val_2['kat_id'] ){
//code...
break;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question