ags_cs4 Posted November 22, 2019 Posted November 22, 2019 today i wanted to change the stupid html mainmenu to somthing good and easy to edit any time so the idea i got was to use multidimensional arrays for fast edit and flexibility. want to learn more? read this topic screenshot: Lets get started in my code i wanted to get flexible links so i can show them when you are in jail or hospital or donators or no mater what condition is with small edits , so in my array i added 2 key one for hospital and one for jail, and the array looks like this You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. so as you can see we have 6 keys 4 of them are for the link html code and the last 2 are our conditions true mean that the link show, and false mean the link is hidden on that condition so lest keep going the idea was so i can show 3 sections 2 are always shown and 1 for only doantors only so i made an array like this: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. we can see we have 3 keys , one for the name of the section, one for our condition which is donator, the last is the array of our links that we worked on them before now lets go to the loop to show our sections You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. so we stored our multidimensional array in a variable named $navigations and we lopped it using foreach we added a condition for 'donatordays' if its true it wont show that section. inside the first foreach we added another foreach to loop our list of links using our 'links' key $navigation['links'] from the first foreach. as you can see we have 2 condition 1 for jail which is big than the current timestamp(my game use timestamp not minutes crons) while the value from the array key "jail" = false, the same thing for hospital. while we have nothing printed inside that if/else of both condition of jail/hospital so that it wont show any link when the condition is true. a full code if you get lost in the way ? You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. in the end this way will make it east to add condition to each link or section with out having to make the html code more confusing by adding more if/else statments PS: this my first time writing an article in english so bear with me 4 Quote
Dave Posted November 22, 2019 Posted November 22, 2019 Nice use of multi dimensional arrays, you could also use PHP short array syntax if you're on a version of PHP which supports it: https://befused.com/php/short-array Quote
KyleMassacre Posted December 14, 2019 Posted December 14, 2019 (edited) You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. A little old but this is kind of what I did. It is similar to what you have but I think this may just be a little bit more flexible for the most part and will pretty much reduce any potential nested ifs Edited December 14, 2019 by KyleMassacre 3 Quote
ags_cs4 Posted December 14, 2019 Author Posted December 14, 2019 look nice and simple ?, better than my stupid code ? 1 Quote
KyleMassacre Posted December 14, 2019 Posted December 14, 2019 1 hour ago, ags_cs4 said: look nice and simple ?, better than my stupid code ? I wouldn’t call it stupid. I actually seen this the other day and was like hmm ? and I just expanded on it is all 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.