PHP - pulling a single value from a multidimensional array

this is probably pretty simple, but I could help with some help.

I am trying to create a small PHP function that will display one form of multidimensional array value when the user uses two drop-down lists to select the row and column of the array.

So, the user will make a choice from the first drop-down list in which row headers will be indicated, and then make a choice from the second drop-down list in which column headers will be indicated. After the selection is made, the function should then output a value for a specific row and column.

I thought I created an array that would work, but unfortunately not. I have 6 rows and 6 columns in my data table.

Also, is there an alternative to jquery or javascript?

Just find a few pointers to make me walk the path.

Thanks in advance,

Micanio

+3
source share
3 answers

You can do this on the server side or through JS.

JS: update the hidden field of the script with the value using the onChange () event in the dropdowns. Then just capture this hidden field when the form is sent back to the server (the source always checks for valid data).

PHP: the form will provide two values $_POST['field1']and $_POST['field2'](which, of course, you will sanitize before use). The script can define a multidimensional array so you can pass these two values ​​to:

$finalValue = $mdArray[$SanitizedField1][$SanitizedField2];

From there, just save the $ finalValue, whatever you want.

+1
$data = array();
for ($i=0;$i<6;$i++) {
    $data[$i] = array();
    for ($j=0;$j<6;$j++)
        $data[$i][$j] = rand(0,100);
}

, , .

...

echo $data[0][3];

, 0-5, .

0

If I understand your question correctly, you need something like the user selects a drop-down list. Once selected, the option fills the second list. An example of a real world is a user choosing in a country to fill out a form and filling out a drop-down list of states.

This functionality is usually performed using javascript not server side php.

http://javascript.internet.com/forms/country-state-drop-down.html

0
source

Source: https://habr.com/ru/post/1731572/


All Articles