Yesterday I learned "named capture groups" 🙂
To implement what I've learned, I have a 100% perfectly working preg_match_all which goes like this:
$result = 'big paragraph listing Main Part Number and their attributes (colors, weights, etc.)';
preg_match_all("/(?<Main_Number>\d{16}).*?\<td\>(?<origin>.*?)\<br\>(?<color>.*?)\./",$result,$matches);
The array "$matches" has the Main Numbers and their respective attributes all really separate from each other in groups (like a group of Main Numbers, a group of origins, and a group of colors).
Isn't there some way to actually "assign" those attributes to their respective Main Numbers? Maybe by somehow creating a brand new array out of the "$matches" array?
And, maybe this brand new array could be indexed on the Main Numbers.... so that echoing $Main_Number['origin'] would yield "USA".... or echoing $Main_Number['color'] would yield "GREEN?"
I've been trying to figure this out myself by doing things like
for($i=0;$i<count($matches['Main_Number']);$i++) {
$matches['Main_Number'] = $matches['origin'][$i],$matches['color'][$i],$matches['weight'][$i];
}
...but all I get are errors because I don't know what I'm doing :queasy:
Is there any way to create a new array indexed on "Main_Number" ?