Because I did something STUPID – I tried to “dumb it down” so I could get a quick simple answer, and then I was going to apply the quick simple answer to what I REALLY needed help with. I’m sure I’m not the first to try this tactic – I just have this fear that if I tell my REAL question, it will scare everybody away and I’ll get NO answers… :-X
Anyway, my tactic backfired (obviously :’( )… so now I’ll “tell the truth” and explain what I really need.
Using a handheld scanner, I scan the barcode numbers from the back cover of my Used Textbooks into the textarea of my web-based PHP script form. Like this:
1234567890
2345678901
2345678901
2345678901
1234561231
3333333333
3333333333
As you can see above, there can be duplicate books.
Books, by default, are USED.
However, if some books are NEW, I scan a special “666” barcode right after I’ve scanned the new book.
For example, if the first book, second book, and the last book are NEW, here is what the scan would look like:
1234567890
666
2345678901
666
2345678901
2345678901
1234561231
3333333333
3333333333
666
Here is the “PHP Help” I need your help with.
Using the 2nd example above (where I scan the “666” because some of the books are NEW) After I click the “Submit” button, I want the result to look exactly like this:
1234567890: 0 used, 1 new
2345678901: 2 used, 1 new
1234561231: 1 used, 0 new
3333333333: 1 used, 1 new
Because I have NO knowledge about arrays, I really need your help. I know your answer will probably look something like this:
<?php
#I already know how to get the textarea data into an array:
#
$data = explode(',',preg_replace("/[, ]+/",',',strtoupper(preg_replace("/[[:space:]\n\r]/i",',',$data))));
# Because I'm dumb about arrays, I am clueless what to do next. Please don't tell me to unplug my computer and take it back :D