2017-03-01 6 views
2

を使用して新しい配列では珍しい文字列を格納します。私はそれが配列内に存在しない場合は、文字列を表示したいreorder_strは2つの配列を比較して、私は値を持つ2つの配列を持って下にPHP

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 }?> 

私の予想出力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. 
    ) 

-

アレイ1 (reorder_str)。私はこのように試みたが、うまくいかない。 私の配列3は、2つの配列からアンコモン文字列を格納する必要がありますし、新しいショーは、私がarray_diffin_arrayで試してみましたadvance.Meanwhileの空または未定義value.Thanksを持っていないが、私は正確な答えを得ることができませんでした。あなたの予想出力あたりとして

+1

を働いていることは、私の更新質問 –

+0

を投稿してください、あなたは私たちに期待される出力を提供してくださいできますか? –

+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

+0

私にとっては、arr2配列からすべての値が返されました。 –

+0

私は自分の答えで共有したリンクをチェックしましたか? – rahulsm

+0

私はlink.Butそのは私diffの出力 –

関連する問題