PHP declaring global variables in function -
I've been on it for two hours, maybe I can give some help.
OK, so I have a basic $ _POST variable that the user submits as you can see below, the code first checks that the value was submitted at all, and if it was a default Value is not set to If the user has submitted a value, then it sets a variable (used later) to submit the value you can see below your code.
if (! Isset ($ _ POST ['psize'])) {$ pSize = "16"; } And {$ pSize = ($ _POST ['pSize']); }; Copy $ pSize; The problem with the above is that I will have 50 or so different areas which the user will submit, and this will only be suitable for myFunction ('name'), 'default', 'value');
to write above for each region. However, I'm running into a problem. Here are some things I'm trying to do. (Sorry for any small errors; I do not have the actual code, which I was trying to do. Function new function ($ title, $ default, $ value) if (! Isset ($ _ POST [$ value]) ) {$ Title = $ default;} and {$ title = ($ _POST [$ value]);}; newFunction ('pSize', '16, '24'); copy $ pSize;
I soon came to know that the above fact is that the variable in the function will not work unless it becomes global. This is understandable, because if the variable $ title
Can be used, so it will be set on many different things, depending on how often I called the function. In keeping with these things, I try to set the global variable Function. New function ($ headline, $ default, $ value) if (! Isset ($ _ POST [$ value])) {global $ title 'title' = $ title; ... new function ('piece ize', '16, '24'); copy $ pSizeTitle;
I finally created the global variable < Code> $ title , which was supplied for the function with the string 'title', which is the new global variable pSizeTitle
, so that variable I can resonate and it really worked really, except for the fact that I can not write anything by adding a global variable at the end, with only a simple name, and it will not work for me because I Every title
items are available to me Seventeen.
Hope this is clear, sorry, if this is a full Noble problem, then I can not really find it.
I think the big problem is that you are not returning any data to your function, Try doing this
function new function ($ heading, $ default, $ value) {if (! ($! _ $ POST [$ value])) {$ title = $ default ; } And {$ title = ($ _POST [$ value]); } $ Heading; // Return was missed}
Comments
Post a Comment