![]() |
Problem with Arrays
Im having a small problem with arrays, this code used to work, but now i get something like
Code:
Notice: Undefined offset: 1 on line 69Heres the code, in short it gets the categories from the db, and splits them into 4 columns. Im pretty sure the error is because im trying to pull from an empty array. The errors only occur when the amount of categories are not directly divisable by 4. |
That's a crazy bit of PHP code. What the hell is going on? :-) And why are you doing it like that? And what does it achieve?
|
lol it takes a list of categories returned from a db query. Then i am arranging it in 4 columns. But i want them in alpha order going down instead of across. So i had to come up with this crazy work around. I couldnt figure out another way to do it.
But the problem is when it trys to push on an empty value on these lines Code:
for ($x=0;$x<$tot_rows;$x++) { array_push($byFours1, $subs[$y]); $y++; }I hope thats a little more clear. |
Do you have your server set to E_STRICT? and ++$var us faster then then $var++
|
Like TlcAndress just said, maybe you should try using
error_reporting( E_ALL ^ E_NOTICE ); for your debugging.So, what you want to do is retrieve a 1D (one dimensional array as we call it at work) and filter every value depending on the row name. For example; PHP Code:
Else, from another perspective, you want to sort every value? Or push it into 4 different arrays? You should take a look at PHP: Arrays - Manual. That might solve some of your issues. I advise you to read them carefully since I use a lot of them for different tasks. I hope this helps. |
Use a query to fetch the data already ordered, put all that data into one big array, then use array_slice to "cut" the big array into 4 pieces...this is a less trickier way to achieve what I believe you want to achieve. There are other ways, but I'm too tired to come up with a more efficient solution right now...
|
Well i finally figured it out. I ended up just adding '' to the array if there were not any more values to add. Thanks for the suggestions though.
|
| All times are GMT. The time now is 06:51 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0