下面我有两个带数值的数组。
数组1 - reorder_str
Array (
[0] => A aacomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[1] => A eecomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[2] => defined
[3] => defined
[4] => defined
)
数组2 -reorder1
Array (
[0] => A bbcomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[1] => A cccomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[2] => A aacomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[3] => A ddcomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[4] => A eecomputational agent is considered intelligent if it can adapt its actions to a particular setting.
)
<?php if(in_array($reorder1[0], $reorder_str)){
?>
<div class="qitem di">
1.<?php echo $reorder1[0];?>
</div>
<?php }?>
我的预期输出数组3
Array (
[0] => A bbcomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[1] => A cccomputational agent is considered intelligent if it can adapt its actions to a particular setting.
[2] => A ddcomputational agent is considered intelligent if it can adapt its actions to a particular setting.
)
我想显示字符串,如果它不在数组中(reorder_str)。我试过这样但是它没有用完。
我的数组3应该存储来自两个数组的Uncommon字符串,而new show没有任何空值或未定义的值。提前谢谢。同时我尝试使用array_diff
,in_array
,但我无法得到确切的答案。 / p>
答案 0 :(得分:3)
根据您的预期输出检查此代码,
$arr1 = array(
0 => "A aacomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
1 => "A eecomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
2 => "defined ",
3 => "defined ",
4 => "defined ",
);
$arr1 = array_map('trim', $arr1);
$arr2 = array(
"0" => "A bbcomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
"1" => "A cccomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
"2" => "A aacomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
"3" => "A ddcomputational agent is considered intelligent if it can adapt its actions to a particular setting.",
"4" => "A eecomputational agent is considered intelligent if it can adapt its actions to a particular setting."
);
$arr2 = array_map('trim', $arr2);
$result = array_diff($arr2,$arr1);
print_r($result);
这是有效的link