If I have an array of strings, how can I reduce it by filtering out any strings that are prefixes of other strings in the array?

For example, if I start with this array:

```
$array = array('123', '234', '1234', '2345', '123456', '345', '1', 
               '12', 'six', 'one/two/three','six/seven','one/two');

```

I am trying to end up with this array:

```
$new_array = array('123456', '2345', '345', 'six/seven', 'one/two/three');

```

Because `'12345'` starts with `'1234'` which starts with `'123'`, etc.

I think I need to loop strings from the array and if the string length is bigger and it begins with the previous string, then replace the old string with the new string.

I would like to use this code

```
foreach ($array as $string) { 
    // compare with previous strings
    $new_array[] = $string; // replace prefixes of $string
}

```

but I do not know how to do the comparison. How can I accomplish this?