How to transfer a lot of options in "for" operator
Hello, I have a lot of options and I want to save space and turn them into "for" operator, but I dont know how... I tried but there isn't effect...
Simple Example Code
I want to do something like that, but now there isn't effect: PHP Code:
|
Re: How to transfer a lot of options in "for" operator
just a heads up, just because the second code "looks better" it's actually worse in terms of optimization since you're uselessly adding two loops in there
this is micro optimization, aka it doesn't directly affect the server, but still, it's good not to get used to such practices as when they add up they start impacting the server |
Re: How to transfer a lot of options in "for" operator
Didn't understand...
|
Re: How to transfer a lot of options in "for" operator
If you tell us about what exactly you are doing we could help you optimizing your code. For example, what is iItem, g_option, etc.
As aron9forever said, if there are just 3 conditionals would be better to leave it as the first example. |
Re: How to transfer a lot of options in "for" operator
I want exactly to change the content of menu_cb function to for operators. Something like 2nd code, but correctly written. No there are more options, just I want to see example.
|
Re: How to transfer a lot of options in "for" operator
Quote:
|
Re: How to transfer a lot of options in "for" operator
You already have a lookup table that is indexed by your item numbers. If your code is more complex than the example you provided, you should always look towards crafting this type of setup, where you simply retrieve from an array index - it doesn't matter if it is of constant size or dynamic. If you have a case where you feel that a for loop is actually necessary, you need to update your example and show us.
Code:
|
Re: How to transfer a lot of options in "for" operator
Quote:
EDIT(sorry, double posting):
That's the example
I can't explain it better. |
Re: How to transfer a lot of options in "for" operator
What Nextra provided should do the trick as long as your sample code is accurate to what you're trying to do.
|
Re: How to transfer a lot of options in "for" operator
Quote:
Code:
A loop would unnecessarily complicate things. You need to do something based on a single value, and you have the means to directly derive the necessary information from that single value. You don't need to search for anything, you don't need to iterate. A lookup-table is perfect for this, and you already have it in place. You just need to use it properly. |
All times are GMT -4. The time now is 08:42. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.