[eluser]stef25[/eluser]
Nested foreach will absolutely cause problems like this. I had the same problem on a site of mine. With 10 rows of test data I didn't notice it but with 300 rows of real data it took 5+ sec to load the page. And that was with only 2 levels of foreach, you have three.
If the first array contains 1000 elements and the second one does too then you have 1000 x 1000 iterations = 1.000.000 loops. Add another 1000 in your third array and you have a billion iterations. Put a counter on it to make sure I'm not wrong.
If you change your code to foreach($kategorije as $k) print_r($k) then I'm sure it will be less than a sec. Since you have no queries, it can not be much else than nested foreaches