Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:39:32+00:00 2026-05-23T23:39:32+00:00

Please consider this example Array ( [1] => search engine optimization [2] => engine

  • 0

Please consider this example

Array
(
   [1] => search engine optimization
   [2] => engine optimization
   [0] => search engine
)

I want to remove engine optimization and search engine because these words are already in the longest phrase. These words are not hard coded, the above result is generated by a function. I did my best to code it but couldn’t solve this problem.

EDIT

This is my attempt, looks like people here don’t trust and they are good at pressing vote down button. My approach is not adequate so I didn’t bother to share it here.

$result = array('search engine', 'search engine optimization', 'engine optimization');
uasort($result, 'string_word_length');

foreach($result as $key=>$phrase) {
  if( ($found = array_find($phrase, $result, $key)) != FALSE) {
     unset($result[$found]);
  }
}

function array_find($needle, $haystack, $skip_key = 0) {
    if(!is_array($haystack)) return false;
        foreach($haystack as $key=>$value) {
            if($skip_key != $key && strpos($value, $needle)!==false) {
                 echo 'Poped ', $value, ' -- ', $key, ' -- ', $skip_key, '<br />';
                 return $key;
           }
    }
   return false;
}
function string_word_length($a,$b){
   return strlen($b) - strlen($a);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:39:33+00:00Added an answer on May 23, 2026 at 11:39 pm

    What about this (supposing you use php >= 5.3):

    $src = array('search engine optimization',
        'engine optimization',
        'search engine');
    
    $src_array = array();
    foreach ($src as $val) {
        $src_array[] = explode(' ', $val);
    }
    
    usort($src_array, function($a, $b) { return count($a) > count($b); });
    
    foreach ($src_array as $key => $val) {
        if ($key + 1 < count($src_array)) {
            foreach ($val as $word_key => $word){
                for ($i = $key + 1; $i <= count($src_array) - 1; $i++) {
                    if (in_array($word, $src_array[$i])) {
                        unset($src_array[$key][$word_key]);
                    }
                }
            }
        }
    }
    
    $result = array_filter($src_array, function($i) { return count($i) > 0; });
    $result = array_map(function($i) { return implode(' ', $i); }, $result);
    $result = array_values($result);
    
    var_dump($result);
    

    For those who doesn’t have php 5.3 installed here is the output result: array(1) { [0]=> string(26) "search engine optimization" }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please consider this example. (PHP) class Database{ private $result; private $conn; function query($sql){ $result
Please consider this example: ( working example ) Style declarations: body {background:#333;font:1em Arial, Helvetica,
Please consider this class: class A { public: //public in this example string a1;
consider this example please int i=11, j=5; boolean b=true, c=false; System.out.println(b&c); // --> output=false
please consider this reproducible example: from PIL import Image import numpy as np import
This is a complex question, please consider carefully before answering. Consider this situation. Two
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
Let me illustrate this with an example. Consider there are 10 books (there may
Please, consider the following (I'm sorry for the amount of code; but this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.