duancaoqin6683 2016-06-26 09:43 采纳率: 0%
浏览 34
已采纳

检查每个阵列上的相同单词

I want to check that a string contains the same word when comparing 2 different array's. If there is the same word on each array it will show how many on each inside multidimensional array

Array one is common array type and array two is multidimensional array

Array 1:

Array
(
    [0] => royalty
    [1] => free
    [2] => picture
)

Array 2:

Array
(
    [0] => Array
        (
            [0] => Affordable and search from millions of royalty free picture
        )

    [1] => Array
        (
            [0] => from millions of royalty picture
        )

    [2] => Array
        (
            [0] => Provides free picture upload and hosting
        )

    [3] => Array
        (
            [0] => Post your picture here Get permanent links
        )

    [4] => Array
        (
            [0] => Choose your own unique username to access image
        )

)

Result:

Array
(
    [0] => Array
        (
            [0] => 3
        )

    [1] => Array
        (
            [0] => 2
        )

    [2] => Array
        (
            [0] => 2
        )

    [3] => Array
        (
            [0] => 1
        )

    [4] => Array
        (
            [0] => 0
        )

)

From the above example, array contain each word of royalty free picture will show how many word the same in each inside multidimensional array

I was trying it using strcasecmp() but it just give me 0 results if two string contains same word and I think it can't give right result for string with so many words.

  • 写回答

2条回答 默认 最新

  • doufangmu9087 2016-06-26 10:00
    关注

    Split string and find intersection with the array of seached words

    foreach($array2 as &$item)
       $item[0] = count(array_intersect($array1, explode(' ', $item[0])));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测