CodeIgniter Forums
Valid IF statement expressions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Valid IF statement expressions (/thread-67829.html)



Valid IF statement expressions - onezeroone - 04-14-2017

Hi all,

I have a CodeIgniter project is currently functioning correctly but i'm not sure how one statement is executing. Here it is:

some_controller class 
If($this->some_model->some_check($email) { execute some code     }

some_model class
public function some_check($email)
{
  $this->db->where('email',$email)'
  return $this->db->get('email_table')->row_array();
}


What i'm confused about is the some_check method, it returns "row_array()" - how does this pass as a condition for the if statement?

Any help appreciated.


RE: Valid IF statement expressions - Martin7483 - 04-14-2017

row_array returns the requested row or NULL

Quote:row_array([$n = 0])
 
   Parameters: $n (int) – Index of the query results row to be returned

   Returns: The requested row or NULL if it doesn’t exist
   Return type: array

   Returns the requested result row as an associative array.

   Usage: see Result Rows.

If the return value is not NULL it should pass as TRUE


RE: Valid IF statement expressions - Paradinight - 04-14-2017

(04-14-2017, 10:05 AM)onezeroone Wrote: Hi all,

I have a CodeIgniter project is currently functioning correctly but i'm not sure how one statement is executing. Here it is:

some_controller class 
If($this->some_model->some_check($email) { execute some code     }

some_model class
public function some_check($email)
{
  $this->db->where('email',$email)'
  return $this->db->get('email_table')->row_array();
}


What i'm confused about is the some_check method, it returns "row_array()" - how does this pass as a condition for the if statement?

Any help appreciated.

http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

An empty array is false.


RE: Valid IF statement expressions - Narf - 04-18-2017

(04-14-2017, 11:18 AM)Paradinight Wrote:
(04-14-2017, 10:05 AM)onezeroone Wrote: Hi all,

I have a CodeIgniter project is currently functioning correctly but i'm not sure how one statement is executing. Here it is:

some_controller class 
If($this->some_model->some_check($email) { execute some code     }

some_model class
public function some_check($email)
{
  $this->db->where('email',$email)'
  return $this->db->get('email_table')->row_array();
}


What i'm confused about is the some_check method, it returns "row_array()" - how does this pass as a condition for the if statement?

Any help appreciated.

http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

An empty array is false.

It's impossible to get an empty array here.


RE: Valid IF statement expressions - Paradinight - 04-18-2017

(04-18-2017, 02:30 AM)Narf Wrote:
(04-14-2017, 11:18 AM)Paradinight Wrote:
(04-14-2017, 10:05 AM)onezeroone Wrote: Hi all,

I have a CodeIgniter project is currently functioning correctly but i'm not sure how one statement is executing. Here it is:

some_controller class 
If($this->some_model->some_check($email) { execute some code     }

some_model class
public function some_check($email)
{
  $this->db->where('email',$email)'
  return $this->db->get('email_table')->row_array();
}


What i'm confused about is the some_check method, it returns "row_array()" - how does this pass as a condition for the if statement?

Any help appreciated.

http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

An empty array is false.

It's impossible to get an empty array here.

True. My mistake. row_array return null not array().

@onezeroone null is a false value. See the php manual link in my post.