Hi-

I am having difficulty working with an array in php and would appreciate any help...thanks in advance!

I have queried my database to return all product ids with type 'book' and id base 'brd'. The product id is a string that is formatted as follows: <base><3 or 4 digits><no letter or A or B or C...> (e.g., brd805, brd805A, brd805B, brd1002, brd105B).

I would like to make a new version of the array where the numeric part is unique. In the example below, I would like to remove 'brd805A' and 'brd805B' from the array because 'brd805' exists. ...but I want to keep 'brd142B' in the array because there is no 'brd142'...

Is my only option to loop through the array in php, compare the numeric portion and then create a new array based on findings?

Is there a regular expression I could use in my sql query to output the corrected array rather than trying to work with it in php?

example output from my database query:
array (
0 =>
array (
'ID' => 'brd805',
'Type' => 'book',
),
1 =>
array (
'ID' => 'brd805A',
'Type' => 'book',
),
2 =>
array (
'ID' => 'brd805B',
'Type' => 'book',
),
3 =>
array (
'ID' => 'brd823',
'Type' => 'book',
),
4 =>
array (
'ID' => 'brd1023',
'Type' => 'book',
),
5 =>
array (
'ID' => 'brd142B',
'Type' => 'book',
),
)

I realize I can use regexp in sql and in php, just couldn't find an expression to use... Is there an expression that you have in mind?
thanks-

This article has been dead for over six months. Start a new discussion instead.