count - In PHP can I get the total number of case statements in a switch statement? -


Is there a way to return the examples of the total number (case) in the switch switch statement? Something like this:

  $ id = $ _GET ['id']; Switch ($ ID) {case "item1": $ data = 'something1'; break; Case "item2": $ data = 'some 2'; break; } $ Echoing data;  

But for this logic there are many files in these switch statements, but the number of them varies depending on the file. I ideally want to increase the "id" and loop through these switch statements. If possible, any ideas?

If you are specifying prices only on the basis of the second value, use instead:

  $ idToData = array ('item1' = & gt; 'some 1', 'item2' = & gt; 'some2',); $ Data = 'default'; If (isset ($ _GET ['id']) & amp; amp; amp; amp; amp; and_key_key_exists ($ _GET ['id'], $ idToData)) {$ data = $ idToData [$ _GET ['id']]; } $ Echoing data;  

The advantage of an array is that it can be and the number of objects can be counted with


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -