jackgoddy123 Posted July 25, 2014 Share Posted July 25, 2014 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 More sharing options...
Psycho Posted July 25, 2014 Share Posted July 25, 2014 I don't understand what it is you are trying to accomplish Link to comment https://forums.phpfreaks.com/topic/290113-php-logic-code/#findComment-1486146 Share on other sites More sharing options...
Psycho Posted July 25, 2014 Share Posted July 25, 2014 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.