I have array in PHP and I have problem with remove some elements from this array. It looks like this:
Array
(
[0] => 2x 633130A
[1] => 2x 525130B
[2] => 2x 591130B
[3] => 2x 963130B
[4] => 2x 813130B (20mm)
[5] => 2x 813130B
[6] => 2x 313130B (12mm)
[7] => 2x 313130B
[8] => 4x 413130B
[9] => 2x 633130B
[12] => 2x 381130A (23mm)
[13] => 2x 381130A
)
And now I'd like to remove this repeated elements without mm parameter as you can see below:
FROM =====> TO
Array Array
( (
[0] => 2x 633130A [0] => 2x 633130A
[1] => 2x 525130B [1] => 2x 525130B
[2] => 2x 591130B [2] => 2x 591130B
[3] => 2x 963130B [3] => 2x 963130B
[4] => 2x 813130B (20mm) [4] => 2x 813130B (20mm)
[5] => 2x 813130B <= REMOVE [5] => 2x 313130B (12mm)
[6] => 2x 313130B (12mm) [6] => 4x 413130B
[7] => 2x 313130B <= REMOVE [7] => 2x 633130B
[8] => 4x 413130B [8] => 2x 381130A (23mm)
[9] => 2x 633130B )
[12] => 2x 381130A (23mm)
[13] => 2x 381130A <= REMOVE
)
I tried array_unique doesn't work in this case, because elements are not exactly the same. Can anybody help me how to delete those repeated elements?
n+1
has "mm" in it and deleting itemn
array_search('mm)', $array)
for all keys, take this values,substr
them to needed value 2x 813130B (20mm) -> 2x 813130B; after itarray_search
this values and unset them. I think it can be improved.