Jump to content

Recommended Posts

My form's "Textarea" receives this data (exactly like this, scanned straight from the childrens toys :pirate: ):

 
dog,white
cat,white
cat,black
cat,white
dog,black
bird,white
 
After clicking "submit," the desired result is a tidy list that has to look just like this:
 
bird: 1 white
cat: 2 white, 1 black
dog: 1 white, 1 black
 
Well, I've ruined all last weekend, all of monday, all of tuesday, and most of today trying to figure this out. The tricky parts for me is getting php to "keep count" like the cats (2 white, and 1 black). So therefore I humbly come to you all and ask for the code, which is probably a super-simple one-liner that will make me feel foolish  :tease-03:  Please help?  ::)
 
Link to comment
https://forums.phpfreaks.com/topic/298477-can-php-count-white-and-black-cats/
Share on other sites

By the way, the one-liner:

$input = "dog,white
cat,white
cat,black
cat,white
dog,black
bird,white";

$output = current(array_map(function($i){return ksort($i)&&array_walk($i,function(&$v){$v=implode(": ",array_reverse(func_get_args()));})?implode("\n",$i):array();},array(array_map(function($i){return arsort($i)&&array_walk($i,function(&$v){$v=implode(" ",func_get_args());})?implode(", ",$i):array();},array_reduce(preg_split('/\r\n?|\n/',$input),function($c,$i){return@++$c[strtok($i,",")][strtok("")]?$c:$c;},array())))));

echo $output;
Obfuscated a bit so it's longer than it needs to be.
  • Like 2

I'm always so nervous asking for help because you all will yell at newbies for "asking for FREE help." And usually the answers suck, because you'll say something like "go to www.php.net/complicated_arrays" and tell me to "study up."

 

Therefore, how about this -- if someone wants to Private Message me, I will offer a one-time PayPal amount (if both you and I agree on) to just ONE person who will write the lines of code I want.

This isn't Rent-a-Coder.

 

Multiple users have offerered to go through your current code and help you fix the problems. Appearently you don't want that (or maybe there never was any code in the first place). You want somebody to write a “super-simple one-liner” for you while you sit back and relax. It doesn't work like this.

you all will yell at newbies for "asking for FREE help."

That's exactly what this is - free help. We volunteer our free time to help people. The least you could do is show some appreciation. Also, nobody is yelling, except for you.

 

And usually the answers suck, because you'll say something like "go to www.php.net/complicated_arrays" and tell me to "study up."

Yeah, that's how programming works. You have to be willing to look at a technical document and learn the material. You can't just write what people tell you to write - that's not how it works. By directing you to the manual, we are giving you the materials and resources to actually learn how certain things work, and become a better developer.

 

The point of this forum is to help people through problems with their code. The key phrase here is "their code". You didn't post any code. You said you spent 3 days working on it, so, what do you have to show us? Where are you stuck specifically? This forum is not, "hey I have this problem, can somebody write the solution for me?" If that's what you want, post in the Job Offerings section and pay for the work. But don't come here demanding free answers and then berate the people that give you the answer you don't want to hear.

  • Like 2

Ok, heres the real deal that I got from another forum site. She is using a handheld scanner to scan barcodes on books and putting all the scan data into one text box. No details on the scanner. Pretty sure their is a better option for the scanner output then dumping it all to one textarea.

PLEASE BAN ME AND DELETE ALL THESE POSTS i FEEL LIKE i HAVE WALKED INTO A ROOM OF HALF-ASLEEP ZOMBIES AND NONE OF YOU EVEN READ MY POST, LIKE THE IDIOT BARAND TELLING ME HOW TO "<PRE>" THE TEXTAREA INPUT LIKE THAT ISN'T EVEN WHAT I WANTED.

JACKQES MY GOD YOU TAKE THE CAKE AS FAR AS RUDEST ON THE PLANET.

You are the only person in this thread that has been rude. The rest have given helpful advice and suggestions, and even wrote code samples doing what you asked for - even though you provided nothing on your end.

 

If you would like help in the future I recommend you actually put forth some effort on your part - instead of throwing a temper-tantrum when you aren't spoonfed the solution to your problems.

  • Like 1
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.