How do I create substrings from an array using PHP?

Posted by mike on Stack Overflow See other posts from Stack Overflow or by mike
Published on 2010-04-19T21:06:30Z Indexed on 2010/04/19 21:23 UTC
Read the original article Hit count: 148

Filed under:
|

I have an array of data that looks like this:

2008, Honda, Accord, Used, Car

And I'm trying to figure a way to make a number of sub strings from each item in the array. For example, I would like to loop each item and create the following substrings:

2008
2008 Honda
2008 Accord
2008 Used
2008 Car
2008 Honda Accord
2008 Honda Used
2008 Honda Car
2008 Accord Honda
2008 Accord Used
2008 Accord Car
2008 Used Honda
2008 Used Accord
2008 Used Car
2008 Car Honda
2008 Car Accord
2008 Car Used
Honda
Honda 2008
Honda Accord
Honda Used
Honda Car
Honda 2008 Accord
Honda 2008 Used
etc ...

I need to make sure that there are no duplicates created and I need to prevent it from adding the same word twice (ex: Honda Honda OR 2008 Honda 2008 - i dont want that). Has anyone wrote anything like this or know where I can find a script that works the same way?

© Stack Overflow or respective owner

Related posts about php

Related posts about array