2

いくつかのコメントフィードで作業しています。2 つの配列 arrayone にはコメントがあり、arraytwo には自己定義値があります。arraytwo の値が arrayone に存在する場合、その値は arrayone から削除する必要があります。

それらはここにあります

    $arraytwo  = array("cool","lo","love");

   $arrayone = Array
    (
        [0] => Aman Namdev Twinkle::how many coast  ,
        [1] => Remi George::cool  ,
        [2] => Swaraj Kumar::wow mind blowing ,
        [3] => Aman Nagar::nice ,
        [4] => Aarya Kumar::H  ,
        [5] => Akash Shah::superb ,
        [6] => Varadraj Nayak::in my city i will get it at 450 D i hav D D ,
        [7] => Ronak Prajapati::prize koti che 400 rs ma male bro ,
        [8] => Praveen Bahukhandi::dikhne me kam nahi kho jayein to gam nahi D ,
        [9] => Keimah Prince Pachuau::it s my type i have three pieces ) ,
        [10] => Chetan Singh::niceeeee  ,
        [11] => Abdus Salaam::Best 1 ,
        [12] => Jagan Nath::Wow nice  ,
        [13] => Tanmay Sankhe::1no banntta  ,
        [14] => Prashant Bhesaniya::Good  ,
        [15] => Yogender Tanwar::nycc waferers ,
        [16] => Ophil Goyal::fuck off 1 months bhi ni chalen gi ,
        [17] => Tarun Khatri::how many coast  ,
        [18] => Jassu Jaz::sexy ,
        [19] => Suraj Khanna::cool  ,
        [20] => Aap Kis "gaon" Se Hain::https www facebook com pages Aap Kis gaon Se Hain 522063624503084 ref hl like dis page ) ,
        [21] => Amit Kumar::https www facebook com LearnAdvanceGeneralKnowledge ref stream&hc location stream ,
        [22] => Sayan Ghosh::awesome  ,
        [23] => Salman Akhtar::n p ,
        [24] => Ashish Kumar::pareshan mt ho le lungaaa ,
        [25] => Vishesh Maheshwari::really like it where can be found it  ,
        [26] => Girjesh Pratap Singh-ll::https www facebook com pages We Can Change It If You Are LOve Our Country Then Join US 192400627596130 ,
        [27] => Hiren Prajapati::bhai tara mate 6  ,
        [28] => Vengatesh Kumar::really cool  ,
        [29] => Pabitra Kumar Samal::dont choice ,
        [30] => Mithlesh Oraon::Bhai ye chasma mujhe doge ,
        [31] => Priya Brata Tripathy::hiiiiiiiiiiiii lishaaaaaaaaaaa ,
        [32] => Ravi Ram::How much costs ,
        [33] => Manjunath Bullet::plz call me i wan t this glass my mun 9743001183 ,
        [34] => Sizziling Angel::i have dis glairs ,
        [35] => Nagarathinam Mohan::glasssss ,
        [36] => A.k. Meher::i dont like after one month dmage this sunglas i am use this sunglas ,
        [37] => Ram PArkash Goyal::I love u I love u I love u I wanna spend my life with only You ,
        [38] => Deepak Kumar::its mine ,
        [39] => Sanjay Pareek Monu::rkhe hui acche nhe lgthe lga le  ,
        [40] => Jyothi Budupula::like this ,

    )



   foreach($arraytwo as $sa)
        {
    foreach($arrayone as $fa)
    {

    $result1 = str_replace($sa,"",$fa);

        }

    }
4

4 に答える 4

1

PHP には、文字列値の各配列エントリを調べてから、一致に基づいてフィルタリング (または検索) するのに非常に適した関数が付属しています。

これは、pcre ベースの正規表現拡張機能の一部であり、preg_grep.

あなたの場合、$arryTwo入力を選択して正規表現パターンに変換します。次に、このパターンを使用して$arrayOne、一致を反転して grep します (つまり、一致が削除されます)。

$pattern  = sprintf('~(\\Q%s\\E)~', implode('\\E|\\Q', $arrayTwo));
$filtered = preg_grep($pattern, $arrayOne, PREG_GREP_INVERT);

結果は、フィルター処理された配列 ( demo ) になります。

Array
(
    [0] => Aman Namdev Twinkle::how many coast  
    [3] => Aman Nagar::nice 
    [4] => Aarya Kumar::H  
    [5] => Akash Shah::superb 
    ...

この出力例がここに示すように、エントリ 1 と 2 は除外されます。

チャットで検索を提供したい場合は、同じ機能を使用できます。文字列に関して言えば、正規表現は非常に強力ですが、常に単純であるとは限りません。そのため、文字列検索をより頻繁に処理する必要がある場合は、正規表現について学ぶことに時間をかけてください。

同様に参照してください:

于 2013-08-17T07:36:47.603 に答える
0

事前定義関数を使用するのは非常に簡単です.....

<?php $array1 = array("a" => "green", "red", "blue", "red"); 
      $array2 = array("b" => "green", "yellow", "red"); 
      $result = array_diff($array1, $array2);
      print_r($result);
?>

出力:

配列 ( [1] => 青 )

    I needed to remove the contents of $array1 from $array2 so I tried:

   <?php 
        $diff    = array_diff($members1, $members2);
   ?> 
   WRONG!! A quick swap around and things worked smoothly...
   <?php  
       $diff    = array_diff($members2, $members1); 
  ?> 
  Hope this saves someone a bit of bother
于 2014-08-13T06:51:03.147 に答える