Maybe this will make it easier.
Here was my original code.
foreach ($_SESSION['order'] as $key => $value) {
$found = false;
foreach ($itemsRows as $itemsRow) {
if ($itemsRow['itemId'] == $key) {
$found = true;
break;
}
}
if (!$found) {
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
}
}
I am trying to make my code more efficient and reduce the length of it by changing it to:
foreach ($itemsRows as $itemsRow) {
if (array_key_exists ($itemsRow['itemId'], $_SESSION['order'])) {
echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
}
}
I have information stored in the $_SESSION['order'] array in $key=>$value format. I want to pull information from a database (the $itemsRow). If the information in the array is not in the results from the database I want to print the hidden input field. Not having the $key and $value from my first piece of code is confusing me. I am not sure how to specify this or how to properly do this.
Please let me know if you need further clarification. Thank you very much for your help!