PHP Inserting new data into arrays if it doesn't exist.
Posted on 2012-08-30
I have about 10 categories that change all the time the page is refreshed and therefore, every time the script is loading, I need to insert the category name into array if it does not exist with an integer 1, but if the category already exists in the array, I need to get the integer that represents how many items were counted in that category and increase it by one.
category name = "CAT1" and it doesn't exist, so we add it to the array "CAT1" => "1" means it is the first time we see any item from this category.
now we do the same over and over again and if we see the item with category name CAT1, we should know that we already had one item from that category in the past, so we increase the amount in the array and now we have "CAT1" => "2".
Thank you for help.