Q:

Getting undefined variable using isset

Using the following code, I'm getting the error "Undefined Index: area" 
<select id="area" name="area" class="selectbox dropdownfilter" data-target-id="location">
    <option value="">all areas</option>
    <?php asort($areas) ?>
    <?php foreach ($areas as $code =>$area) : ?>
    <option value="<?php echo $code ?>"<?php if(isset($_SESSION['area']) | isset($_POST['area'])) { if($_SESSION['area'] == $area | $_POST['area'] == $area) { echo ' selected'; } } ?> ><?php echo $area ?></option>
    <?php endforeach ?>
</select>

It's outputting the $area correctly, the error is coming in the 'selected' script. Bit lost as to what I'm doing wrong, or how else I could do it. I'm just trying to select the option if it's what was submitted in the search form.

A:

That condition:
if(isset($_SESSION['area']) | isset($_POST['area'])) {

=> Returns true if $_SESSION['area'] is set OR $_POST['area'] is set
So it is true if $_SESSION['area'] is not set but $_POST['area'] is set, for example.
Then :
    if($_SESSION['area'] == $area | $_POST['area'] == $area) {

=> You are testing $_SESSION['area'] value. If it's not set (it's possible as seen before), you'll have an error notice.
Here is what I'd do, only one condition :
if (
    (isset($_SESSION['area']) && $_SESSION['area'] == $area)
    ||
    (isset($_POST['area']) && $_POST['area'] == $area)
) {

If $_SESSION['area'] is not set, PHP won't bother to test if $_SESSION['area'] == $area because it doesn't need to (as the 1st condition is false anyway), it will try what is after the OR
See http://php.net/manual/en/language.operators.logical.php
And http://php.net/manual/en/language.operators.precedence.php

