It is necessary to display the value of post_max_size , which is specified in the PHP settings

There is such code:

 $size = ini_get("post_max_size"); $letter = $size{strlen($size)-1}; $size = (int)$size; switch($letter){ case 'G': $size *= 1024; case 'M': $size *= 1024; case 'K': $size *= 1024; } echo $size; 

Why multiply megabytes, if it then displays, is not the number?

This is a specialist’s lessons, but how this code works, it did not show and moved on to another topic. Maybe just quickly showed for example?

  • it should give the number of kilobytes in megabytes, for example 4 megabytes will be 4 * 1024 kilobytes - L. Vadim
  • @ L.Vadim in bytes it will output without breaks - teran

1 answer 1

In general, the work of the switch shown here and, in particular, what happens if you do not write break at the end of each case . For by default, falling into one of the branches of the case , if you do not write break , the code will "fall" down and execute the remaining branches, ignoring the underlying instructions. This is the essence of this example (and, by the way, as far as I remember, I saw a lesson and everything is explained there from the beginning of the operator’s work to the task with the information from the file .......... UPD : I even found Video - starting from 3 minutes and up to 30 ... chewed in more detail).

Therefore, if, for example, $letter == 'G' , then the value of size be multiplied by 1024, then it will fall down to M (but the letter will no longer be compared with it, but the instruction will be executed immediately), will again multiply, will fail to K ( the letter will no longer be compared) and multiplied once more. In general, the result of the display will be the display of data in bytes . If this behavior is not needed - "bryaki" are put.