I want to discover whether or not a variable is set. PHP’s isset() function (i.e. isset($myVariable)would ordinarily provide me with the variable’s set status. However, I want to reference the variable as an expression. Is that possible? and if so, how?
A little more context and detail: I have several image submit buttons in an HTML form, each named ‘DeleteFileButtonNNN’ where NNN is an integer (actually, a file ID number). When the user clicks, say, the button associated with NNN=2, the form is submitted and $_POST[‘DeleteFileButton2_x’] gets set (whereas $_POST[‘DeleteFileButton1_x’ and $_POST[‘DeleteFileButton3_x’] will not be set). I want to be able to loop through the $_POST array in order to discover which button was clicked.
I can easily create the boundaries of the loop itself via a while or foreach loop because all possible file IDs (i.e. NNN values) are stored in a MySQL table. My need for help is in how to specify the various DeleteFileButtonNNN elements as array element indices in the $_POST array since the reference would need to be an expression (e.g. a string concatenation such as ‘DeleteFileButton’.$anInteger.’_x’). Yet I don’t believe PHP allows me to reference the $_POST array as $_POST[$someVariable].
Could someone me help please? Thank you in advance.
PHP allows you to use anything that devolves down to an integer or a string to reference an array, so you can most definitely do:
“composite” keys are allowed as well: