只打印定义str_word_count比赛吗? [英] Only print defined str_word_count matches?

查看:133
本文介绍了只打印定义str_word_count比赛吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用(str_word_count($ STR,1));作为一个数组,并让他们忽略了分配了一个数字的话...那么你好[1] =>世界[2] =>这[3] =>是[4] =>一个[5] =>测试)6 只输出我定义了号码,如[1] [2]省略这是一个测试只留下留下的Hello World,或[1]和[6]你好测试。 ..

How can i use (str_word_count($str, 1)); as an array and omit words assigned a number by leaving them out... So Hello [1] => World [2] => This [3] => Is [4] => a [5] => Test ) 6 only outputs the numbers i define, such as [1] and [2] to omit This is a test leaving only leaving Hello World, or [1] and [6] for Hello Test...

推荐答案

您可以做到这一点的 array_intersect 和的 str_word_count 或的 爆炸

You can do that with array_intersect and str_word_count or explode

$input  = 'Hello World This Is a Test';
$allow  = array('Hello', 'Test');

$data   = explode(' ', $input);
// or your way
$data   = str_word_count($input, 1);


$output = array_intersect($data, $allow);
$count  = count($output);

echo 'Found ' + $count;

var_dump($output);

这篇关于只打印定义str_word_count比赛吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆