Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组中的文本搜索 数组 ( [0]=>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动 [3] =>足球 [4] =>一种足球比赛,两队11人试图将球踢入对方球门或将球顶入对方球门 ) [1] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放 [3] =>活动 [4] =>演员 ) [2] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放器 [3] =>提供商品和服务的商业企业活动涉及金融、商业和工业方面 [4] =>玩家参与或精通某种游戏的人 ) [3] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) [1] =>阵列 ( [0]=>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动 [3] =>运动 [4] =>运动 ) [1] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>竞争 [3] =>竞争 [4] =>竞争 ) [2] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>列车 [3] =>通过训练和教学进行训练创建 [4] =>列车公共交通由铁路车辆联运线提供,由机车牵引 ) [3] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>人 [3] =>人 [4] =>人 ) [4] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) >>_Php_Arrays - Fatal编程技术网

Php 数组中的文本搜索 数组 ( [0]=>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动 [3] =>足球 [4] =>一种足球比赛,两队11人试图将球踢入对方球门或将球顶入对方球门 ) [1] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放 [3] =>活动 [4] =>演员 ) [2] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放器 [3] =>提供商品和服务的商业企业活动涉及金融、商业和工业方面 [4] =>玩家参与或精通某种游戏的人 ) [3] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) [1] =>阵列 ( [0]=>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动 [3] =>运动 [4] =>运动 ) [1] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>竞争 [3] =>竞争 [4] =>竞争 ) [2] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>列车 [3] =>通过训练和教学进行训练创建 [4] =>列车公共交通由铁路车辆联运线提供,由机车牵引 ) [3] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>人 [3] =>人 [4] =>人 ) [4] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) >>

Php 数组中的文本搜索 数组 ( [0]=>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动 [3] =>足球 [4] =>一种足球比赛,两队11人试图将球踢入对方球门或将球顶入对方球门 ) [1] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放 [3] =>活动 [4] =>演员 ) [2] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>播放器 [3] =>提供商品和服务的商业企业活动涉及金融、商业和工业方面 [4] =>玩家参与或精通某种游戏的人 ) [3] =>阵列 ( [0]=>足球运动员 [1] =>足球运动员踢足球的运动员 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) [1] =>阵列 ( [0]=>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动 [3] =>运动 [4] =>运动 ) [1] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>竞争 [3] =>竞争 [4] =>竞争 ) [2] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>列车 [3] =>通过训练和教学进行训练创建 [4] =>列车公共交通由铁路车辆联运线提供,由机车牵引 ) [3] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>人 [3] =>人 [4] =>人 ) [4] =>阵列 ( [0]=>运动员 [1] =>运动员接受训练参加体育比赛 [2] =>运动员接受训练参加体育比赛 [3] =>运动员接受训练参加体育比赛 [4] =>运动员接受训练参加体育比赛 ) ) >>,php,arrays,Php,Arrays,嗨 我需要上面显示的数组的php搜索代码。但是搜索不应该是精确的字符串匹配,比如我正在搜索“11播放器”,它应该给我结果数组[0],正如数组[0][0][4]中提到的那样。你需要一个简单的递归搜索函数 << Array ( [0] => Array ( [0] => Array ( [0] => soccer player


我需要上面显示的数组的php搜索代码。但是搜索不应该是精确的字符串匹配,比如我正在搜索
“11播放器”
,它应该给我结果
数组[0]
,正如
数组[0][0][4]
中提到的那样。

你需要一个简单的递归搜索函数

<<
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => soccer player
                    [1] => soccer player athlete who play soccer
                    [2] => sport
                    [3] => soccer
                    [4] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
                )

            [1] => Array
                (
                    [0] => soccer player
                    [1] => soccer player athlete who play soccer
                    [2] => play
                    [3] => activity
                    [4] => actor
                )

            [2] => Array
                (
                    [0] => soccer player
                    [1] => soccer player athlete who play soccer
                    [2] => player
                    [3] => commercial enterprise activity of provide good and service involve financial and commercial and industrial aspect
                    [4] => player person who participate in or be skilled at some game
                )

            [3] => Array
                (
                    [0] => soccer player
                    [1] => soccer player athlete who play soccer
                    [2] => athlete person train to compete in sport
                    [3] => athlete person train to compete in sport
                    [4] => athlete person train to compete in sport
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => athlete
                    [1] => athlete person train to compete in sport
                    [2] => sport
                    [3] => sport
                    [4] => sport
                )

            [1] => Array
                (
                    [0] => athlete
                    [1] => athlete person train to compete in sport
                    [2] => compete compete for something
                    [3] => compete compete for something
                    [4] => compete compete for something
                )

            [2] => Array
                (
                    [0] => athlete
                    [1] => athlete person train to compete in sport
                    [2] => train
                    [3] => train create by train and teach
                    [4] => train public transport provide by line of railway car couple together and draw by locomotive
                )

            [3] => Array
                (
                    [0] => athlete
                    [1] => athlete person train to compete in sport
                    [2] => person
                    [3] => person
                    [4] => person
                )

            [4] => Array
                (
                    [0] => athlete
                    [1] => athlete person train to compete in sport
                    [2] => athlete person train to compete in sport
                    [3] => athlete person train to compete in sport
                    [4] => athlete person train to compete in sport
                )

        )

>>
结果:

 $my_array =
    array(
        array(
            array(
                "soccer player",
                "soccer player athlete who play soccer",
                "player",
                "commercial enterprise activity of provide good and service involve financial and commercial and industrial aspect",
                "player person who participate in or be skilled at some game",
                "soccer football game in which two team of 11 player try to kick or head ball into opponent goal"
            )
        ) ,
        array(
            "soccer player",
            "soccer player athlete who play soccer",
            "player",
            "commercial enterprise activity of provide good and service involve financial and commercial and industrial aspect",
            "player person who participate in or be skilled at some game",
            "soccer football game in which two team of 11 player try to kick or head ball into opponent goal"
        )
    );



    $elements = recursive_search($my_array,"11 player");

    var_dump($elements);
如果您想要没有路径的元素,那么输出将是这样的

Array
(
    [0] => Array
        (
            [path] => /0/0/5
            [value] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
        )

    [1] => Array
        (
            [path] => /1/5
            [value] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
        )

)

我不知道该怎么做阅读文档怎么样?
Array
(
    [0] => Array
        (
            [path] => /0/0/5
            [value] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
        )

    [1] => Array
        (
            [path] => /1/5
            [value] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
        )

)
Array
(
    [0] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
    [1] => soccer football game in which two team of 11 player try to kick or head ball into opponent goal
)