Jump to content

issues with array_key_exists


bsamson

Recommended Posts

Hello. I am having a heck of a time figuring this one out. I have an array (output below) with info loaded. Everytime I run this, the output a blank page, no errors.

 

Just curious, am I missing something? Thanks in advance for any help.

 

 

 

print_r ($tmp_errors) output:

Array
(
    [0] => cust_add1
)
<?php

$styleForErrorBoxes = "style='border: 1px solid #FF0000'";
$tmp_errors = unserialize($result[0]['tmp_errors']);

if ($tmp_errors) {
   if (array_key_exists('cust_email', $tmp_errors)) { $err_cust_email = $styleForErrorBoxes; }
   if (array_key_exists('cust_phone', $tmp_errors)) { $err_cust_phone = $styleForErrorBoxes;  }
   if (array_key_exists('cust_first', $tmp_errors)) { $err_cust_first = $styleForErrorBoxes;  }
   if (array_key_exists('cust_last', $tmp_errors)) { $err_cust_last = $styleForErrorBoxes;  }
   if (array_key_exists('cust_add1', $tmp_errors)) { $err_cust_add1 = $styleForErrorBoxes;  }
   if (array_key_exists('cust_add2', $tmp_errors)) { $err_cust_add2 = $styleForErrorBoxes;  }
   if (array_key_exists('cust_city', $tmp_errors)) { $err_cust_city = $styleForErrorBoxes;  }
   if (array_key_exists('cust_state', $tmp_errors)) { $err_cust_state = $styleForErrorBoxes;  }
   if (array_key_exists('cust_zip', $tmp_errors)) { $err_cust_zip = $styleForErrorBoxes;  }
} 

echo $err_cust_add1;

?>
Edited by bsamson
Link to comment
Share on other sites

Whatever your trying to accomplish, your doing it wrong.

 

Something like

$temp_errors = array();

if (empty(cust_add1))
{
$temp_errors[] ='Address Required';
}

Then

if (count($tmp_errors))
{
    echo "<div class='error'>";
    foreach($tmp_errors AS $error)
    {
    echo "$error<br>";
    }   
    echo '</div>';
}
Edited by benanamen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.