Jump to content

Recommended Posts

Hello,
  I am working on the logic code which returns the values proper as needed combining 1,2,3 arrays.
  But it gives result as combining first two results as well which is not required.
  I want if  $slice contains "ers" at end so $suffix should not add. for which I have used the regex code.
  But it prints onlyy array $slice and $array3 in middle of the output as eg: "Biggest Web Development" ,
"Leading Web Development" , "Best Web Development" as so on after every 9 row.
 
code:
 
<?php

    $slice = array(0=>"Web Development", 1=>"Online Marketing", 2=>"Australian Web Developers", 3=>"Web Designs", 4=>"Custom Web Design", 5=>"Online Marketing",6=>"Internet Advertising",7=>"Professional Web Design",8=>"Web Designing");
	
	$array3 = array(0=>"Biggest", 1=>"Leading", 2=>"Best", 3=>"Top", 4=>"Largest", 5=>"Premier");
	
	$suffix = array(0=>"Agency", 1=>"Provider", 2=>"Service", 3=>"Specialist", 4=>"Experts", 5=>"Company", 6=>"Business", 7=>"Builder", 8=>"Services");
			
		foreach($slice as $slices =>$value)//keywords
		   {
		   	   foreach($array3 as $array3_keys =>$array3_value)//superlatives
			   {
			  
			       foreach($suffix as $suffix_keys =>$suffix_value)// suffixs
					{
					     if((!preg_match("/ers$/",$value, $matches)))				 
                           {
                               echo $array3_value." ".$value." ".$suffix_value."<br/>";
                            }
                       
  
					} 
					 echo $array3_value." ".$value."<br/>";
			   }
		 } 
		   ?>

Please help.

I am really stuck.

 

  
Link to comment
https://forums.phpfreaks.com/topic/290113-php-logic-code/
Share on other sites

After looking at the output, I think I see what you are doing. I think the logic is backwards. Plus, you should not use Regex for this

 

 

$keywords = array(0=>"Web Development", 1=>"Online Marketing", 2=>"Australian Web Developers", 3=>"Web Designs", 4=>"Custom Web Design", 5=>"Online Marketing",6=>"Internet Advertising",7=>"Professional Web Design",8=>"Web Designing");
 
$superlatives = array(0=>"Biggest", 1=>"Leading", 2=>"Best", 3=>"Top", 4=>"Largest", 5=>"Premier");
 
$suffixes = array(0=>"Agency", 1=>"Provider", 2=>"Service", 3=>"Specialist", 4=>"Experts", 5=>"Company", 6=>"Business", 7=>"Builder", 8=>"Services");
 
//Iterate over each keyword
foreach($keywords as $keyword)
{
    //Iterate over each superlative
    foreach($superlatives as $superlative)//superlatives
    {
        //Check if keyword ends in 'ers'
        if(substr($keyword, -3)=='ers')
        {
            echo $superlative . " " . $keyword . "<br/>";
        }
        else
        {
            foreach($suffixes as $suffix)// suffixs
            {
                echo $superlative." ". $keyword ." ".$suffix."<br/>";
            }
        }
    }
}
Link to comment
https://forums.phpfreaks.com/topic/290113-php-logic-code/#findComment-1486147
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.