Below I have two arrays with values.
Array 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
)
Array 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 }?>
My expected output array3
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.
)
I Want to show the string if it is not present in array(reorder_str).I tried like this but its not working out. My array 3 should store Uncommon strings from two array and new show not have any empty or undefined value.Thanks in advance.Meanwhile I tried with array_diff
,in_array
but I couldn't get exact answer.
Check this code as per your expected output,
$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);
Here is working link