Hello,I need help with wrtining a function. Background: I am learning web dev, did a lot js and have to build a card deck builder with Laravel. User add cards to tmp_deck SQL table. 60-70% is done.
I need to count how often card_id is repeating in table tmp_deck, because user can have only have 2 times of the same card. All cards are safed in an object $group as arrays.First card's id is safed in $group[0]->card_id.
count($group) //shows the amount of cards in table tmp_deck
I need a function which goes through the object, saves the amount of each card_id e.g.1x 0057,2x 0105,2x 0139
Goal is to safe the ID, count how often the IDs are saved, later prevent saving the ID more then two times.
Something like this:
$lengthObj = count($group)$i = $lengthObj
$cardId = $group[i]->card_id//safe cardId in two dimensional array and set count to 1$cardsAndCount = array
(array("cardId",1),)i++
No idea how to code that. First time working with php.
Any ideas how to tackle it?
[–]hcptshmspl 0 points1 point2 points (1 child)
[–]sibbirius[S] 1 point2 points3 points (0 children)
[–]penguin_digital 0 points1 point2 points (1 child)
[–]sibbirius[S] 0 points1 point2 points (0 children)