Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 拉雷维尔:用雄辩的语言获得最常用的词语_Php_Mysql_Laravel - Fatal编程技术网

Php 拉雷维尔:用雄辩的语言获得最常用的词语

Php 拉雷维尔:用雄辩的语言获得最常用的词语,php,mysql,laravel,Php,Mysql,Laravel,我有一个表后,它有一个列的内容。内容列是文本。我想通过雄辩的方式获得今天内容中使用最多的单词,假设table name=post,field name=content,试试这个: 将获得表中第一个最常见的内容,并且: $mostUsed = Post::groupBy('content') ->orderBy('content', 'desc') ->count('content'); 将获得从最常见到最罕见的寄存器顺序。顺便说一下,这只是从MySQL到Eloque

我有一个表后,它有一个列的内容。内容列是文本。我想通过雄辩的方式获得今天内容中使用最多的单词,假设table name=post,field name=content,试试这个:

将获得表中第一个最常见的内容,并且:

$mostUsed = Post::groupBy('content')
    ->orderBy('content', 'desc')
    ->count('content');

将获得从最常见到最罕见的寄存器顺序。顺便说一下,这只是从MySQL到Eloquent的一个改编,根据

我想你要找的是这个

注意:由于您没有提供任何表结构,我不知道如何筛选今天的帖子。我希望有一个名为date的专栏

数一数今天用过的所有单词

// array of all the content strings.
$contents = Post::where('date', date('Y-m-d'))->pluck('content');

// final result will be stored here as a key value pair.
// used count against each word.
$word_count = [];

foreach($contents as $content) {

    // array of each word in the content separated by 'space'.
    $words = explode(' ', $content);

    foreach($words as $word) {

        // if the word has already used +1 the count, else set the count as 1.
        $count = array_key_exists($word, $word_count) ? ($word_count[$word] + 1) : 1;

        // set new word count to the array.
        array_set($word_count, $word, $count);
    }
}

$most_used_word = array_search(max($word_count), $word_count);

到目前为止,您尝试了什么?是laravel 5或更高版本吗?内容栏可能与文章正文类似,您想获取所有内容栏中的所有文本,并从中获取最常用的文本吗?谢谢,如果我只想获取htags?什么是htags?
// array of all the content strings.
$contents = Post::where('date', date('Y-m-d'))->pluck('content');

// final result will be stored here as a key value pair.
// used count against each word.
$word_count = [];

foreach($contents as $content) {

    // array of each word in the content separated by 'space'.
    $words = explode(' ', $content);

    foreach($words as $word) {

        // if the word has already used +1 the count, else set the count as 1.
        $count = array_key_exists($word, $word_count) ? ($word_count[$word] + 1) : 1;

        // set new word count to the array.
        array_set($word_count, $word, $count);
    }
}

$most_used_word = array_search(max($word_count), $word_count);