Welcome Guest, Not a member yet? Register   Sign In
How to identify if an array has been defined?
#1

[eluser]Unknown[/eluser]
Hi,

I am getting data from a table and storing it in an array as follows. I run this code based on certain condition.
Code:
if(condition is true)
  $data['Agent'] = $this->db->get('Table Name');

Then, I am using this array to display as follows:
Code:
foreach($Agent as $item)
{
    echo $item['field_name'];
}

This code works fine when the condition is true because in that case my array 'Agent' is defined. However, if the condition is false, my array 'Agent' is not defined and therefore the second piece of code does not work and gives an error message "Message: Undefined variable: Agent".

I would like to first check if my array has been defined and only then display the data. Please help!


Messages In This Thread
How to identify if an array has been defined? - by El Forum - 11-03-2009, 05:06 PM
How to identify if an array has been defined? - by El Forum - 11-03-2009, 05:26 PM
How to identify if an array has been defined? - by El Forum - 11-03-2009, 05:30 PM
How to identify if an array has been defined? - by El Forum - 11-03-2009, 05:59 PM
How to identify if an array has been defined? - by El Forum - 11-03-2009, 06:09 PM
How to identify if an array has been defined? - by El Forum - 11-03-2009, 07:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB