I’ve got a method that’s meant to return a single value. Because ->result() returns an array I’m using the following to return the single value I’d like to get:
return array_pop($this->db->query($SQL)->result())->event_name;
while it works perfectly fine, I’m wondering if there’s something built into CI that maybe I’ve missed in the documentation. I also use this same trick to return a single record:
return array_pop($this->db->query($SQL)->result());
Is there a better way to do this?
row_array()will return you the 1st row found as an array, androw()will return it as an object.So instead of
array_pop, you can use:OR
https://www.codeigniter.com/user_guide/database/results.html