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

  • SEARCH
  • Home
  • 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 911731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:15:37+00:00 2026-05-15T17:15:37+00:00

I have two arrays one with OS’s such as Ubuntu and Windows and another

  • 0

I have two arrays one with OS’s such as Ubuntu and Windows and another with system templates like Ubuntu 5.3 blah blah and Windows XP SP2 blah blah and I need to extract the OS from the system templates array, however it is not always at the start, sometimes it is in the middle or at the end. So how could I loop through one array and check to see if it is there in another array, if so tell me what the OS is.

Example.

OS List

$os = array("Ubuntu", "Debian", "Gentoo", "Windows", "Fedora", "CentOS", "CloudLinux", "Slackware");

Small section of the list of system templates (this will be in an array)

Ubuntu 8.04 x64 LAMP Installation
Ubuntu 8.04 x64 MySQL Installation
Ubuntu 8.04 x64 PHP Installation
x64 Installation Gentoo
Basic Installation Ubuntu 8.03

Which would result give me

Ubuntu
Ubuntu
Ubuntu
Gentoo
Ubuntu

Thanks

  • 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-15T17:15:37+00:00Added an answer on May 15, 2026 at 5:15 pm

    Make a regex out of the list of OS’s to match against each template string, then map over each template string with that regex:

    function find_os($template) {
      $os = array("Ubuntu", "Debian", "Gentoo", "Windows", "Fedora", "CentOS", "CloudLinux", "Slackware");
      preg_match('/(' . implode('|', $os) . ')/', $template, $matches);
      return $matches[1];
    }
    
    $results = array_map('find_os', $os_templates);
    

    array_map() applies the find_os() function to each template string, giving you back an array of matched OS’s.

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

Sidebar

Related Questions

I have two arrays. I'd like to copy ranges of data from one of
I have two arrays. I'd like to merge them into one, but remove the
I have two different arrays, one with strings and another with ints. I want
I have two arrays and I would like to append one to the end
so I have two arrays. one of them looks like this (it's values or
I have two arrays one with fake Japanese characters, another with the English alphabet
I have two arrays one is for names and another is for phone numbers,and
I currently have two arrays one the stores a file name and another that
I have two PHP arrays. One contains a group name and another contains a
I have two arrays, one looks like: [ssewweewewzad0xsis, sasasaasasaas, ddwdwd, ffdfdfdffdfdf, rffrfrfrfrfrrf, rffrfrfrffrfrfrfbyzad0xsis ,

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.