From the course: Functional Programming with PHP

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Tallying votes

Challenge: Tallying votes - PHP Tutorial

From the course: Functional Programming with PHP

Start my 1-month free trial

Challenge: Tallying votes

(electronic techno music) - [Instructor] The second functional programming challenge that we're going to look at is called tallying votes. And here it is. Let's imagine that a local election just took place and the results are contained in this array of names that we have here called all votes. In order to find out who won, we have to tally the votes. Your job is to complete this tally votes function so that it takes this array of votes and converts it into a string keyed array where each key is one of the candidate's names and the value of that key is how many votes that candidate got. In other words, how many times the candidate's name occurred in the all votes array. Now before you get started, there are a few additional rules to this challenge. First of all, you're not allowed to use any kind of for loop to implement this function. You have to do it using only the array functions we talked about in an earlier section.…

Contents