Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php create word pairs from sentence

/*this will get all word pairs next to eachother */
$sentence = "the cat sat down outside";
$sentenceArr = explode(" ",$sentence);
$wordPairs = array();
for($i=0;$i<count($sentenceArr)-1;$i++) {
      $wordPairs[] =  $sentenceArr[$i].'_'.$sentenceArr[$i+1];
}


/*This will get all pairs (ie: all culmintions of two words)*/
$sentence = "the cat sat down outside";                                               
$sentenceArr = explode(" ",$sentence);                                                
$wordPairs = array();                                                                 
foreach($sentenceArr as $kw1=>$word1){                                                
    for($j=($kw1+1);$j<count($sentenceArr);$j++) {                                    
        $wordPairs[]=$word1."_".$sentenceArr[$j];                                     
    }                                                                                 
} 
Comment

PREVIOUS NEXT
Code Example
Php :: Detect the page realod in php 
Php :: php get locale active 
Php :: laravel email validation 
Php :: php include file from another folder 
Php :: Schema::defaultStringLength(199); 
Php :: scirvere su file php 
Php :: how to disable a button in a blade file 
Php :: laravel query relationship nested 
Php :: remove jquery wp 
Php :: php get today at 3pm 
Php :: check array has keys in php 
Php :: laravel compare request domain and app domain and request original domain 
Php :: static variable php 
Php :: php sec to hours/minuts 
Php :: wordpress raw query 
Php :: "IlluminateDatabaseEloquentMassAssignmentException" 
Php :: laravel blade excerpt from body 
Php :: How to run PHP script every 5 minutes 
Php :: ?: php 
Php :: sometimes validation in laravel 
Php :: readable date in php 
Php :: laravel sprintf span in controller 
Php :: php test questions 
Php :: set config key dynamic laravel 
Php :: Cannot modify header information - headers already sent by 
Php :: laravel search function 
Php :: php enablem mod 
Php :: laravel test filter 
Php :: PHP multidimensional array merge recursive 
Php :: laravel 6 use username on url 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =