• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shorthand

#1
[eluser]RESPECT[/eluser]
This is just a general PHP question...Im wondering if this would work:

Code:
$query = $this->db->get_where('portfolio', array('id' => $id), 1)  = (!$query) ? return $query->row() : return false;

Or would I have to do it this way?

Code:
$query = (!is_null($this->db->get_where('portfolio', array('id' => $id), 1))) ? return $query->row() : return false;

Thanks in advance!

#2
[eluser]Colin Williams[/eluser]
What's the point?

If they work, they work, but I would advise against either.

#3
[eluser]RESPECT[/eluser]
well just wondering which one does...im on a really slow pc for a while and my host is down. So im just curious if anyone know if it would work...runtime wise

#4
[eluser]xwero[/eluser]
I think both examples don't work. If you would want to do something like that i think this is the way to go
Code:
return ($query = $this->db->get_where('portfolio', array('id' => $id), 1))? $query->row() : false;

#5
[eluser]wiredesignz[/eluser]
I'm all for shortened code too, and I can understand xwero's example.

Which ever coding style you choose, just make sure it will make sense to you when you read it again in six months time.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.