KJS KJS - 1 month ago 5
MySQL Question

Dynamic $row output from array

I am trying to achieve dynamic $row values from an array, and show them as output. It keeps showing nothing while the values are already there.

This is what I have so far, where:

$row["lg_".$val.""];
should return:

$lg_it


'it' is the $val from the array.

foreach($arrMapCookieToLang as $key => $val) {
$shrtKey = $row["lg_".$val.""];

<input type="text" name="lg_$val" value="$shrtKey">
}


Anyone an idea?

Answer

What you have should result in a syntax error. Try the following:

<?php
foreach($arrMapCookieToLang as $key => $val) {
    $shrtKey = $row['lg_'.$val];
    ?>
    <input type="text" name="lg_<?= $val ?>" value="<?= $shrtKey ?>">
    <?php
}