- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$prices = array( "Red Pants" => 20, "Black Hats" => 15);
$items = "8 Red Pants, 2 Shirts, 6 Black Hats";
preg_match_all("/(?:(\d+) ([\w ])+,?)+/", $items, $matches);
print_r($matches);