I'm struggling with this..
I have a string like this.
$test2 = "AB:001,003;AC:001,003,004,005,008;AD:002,003,004,007,008,009";
It's two letters : 3 digits, (this can repeat) ;
This string will have multiple 2 letter prefixes, and the amount of 3 digit entries will vary.
I need to be able to find a match between a 2 letter prefix and an associated 3 digits number.
EG: Does AD003 exist in the string ? I know 003 appears mulitple times but I'd want to find just AD003, or another match I query for.
I thought converting the string to individual arrays named after the 2 letter prefixes would be the way to go..
$AB = array('001','003');
$AC = array('001','003','004',008);
$AD = array('002','003','004','007','008','009');
I've got as far as exploding it on the ;
and then the :
$parts = explode(";",$test2) ;
foreach ($parts as $value) {
$a[] = explode(":", $value);
}
print_r ( $a );
This results in :
Array
(
[0] => Array
(
[0] => AB
[1] => 001,002,003
)
[1] => Array
(
[0] => AC
[1] => 001,003,004,005
)
[2] => Array
(
[0] => AD
[1] => 002,003,004
)
)
But I don't know how to take it further than that.
I want to be able to search the arrays for specific matches:
if (in_array("003", $AD)) {
echo "Match";
}
If there is an easier way than converting to array to find AD003 in the string, then I'm happy to try that.
Thanks