CodeIgniter Forums
Can someone "translate" this in plain English to me, please? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Can someone "translate" this in plain English to me, please? (/thread-25973.html)



Can someone "translate" this in plain English to me, please? - El Forum - 01-02-2010

[eluser]developer10[/eluser]
Code:
$update['id'] = (!empty($_POST['id'])) ? $this->input->post('id') : null;

i suppose this line allows the id field to be null. however i need it never to be null. if i remove ": null", it throws
the "unexpected ;" error


Can someone "translate" this in plain English to me, please? - El Forum - 01-02-2010

[eluser]Craig A Rodway[/eluser]
It uses the ternary operator to set the value of $update['id'] depending on the return value of testing if $_POST['id'] is empty or not.

If $_POST['id'] is NOT empty, then $update['id'] is set to the POST'd ID; otherwise it is set to null. Think of it this way:

Code:
$result = (condition) ? IF_TRUE : IF_FALSE;

If you want to remove it, just do this:

Code:
$update['id'] = $this->input->post('id');

However:
Quote:The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist.

Input Class


Can someone "translate" this in plain English to me, please? - El Forum - 01-02-2010

[eluser]Blaze Boy[/eluser]
[quote author="cold_fusion" date="1262495063"]
Code:
$update['id'] = (!empty($_POST['id'])) ? $this->input->post('id') : null;

i suppose this line allows the id field to be null. however i need it never to be null. if i remove ": null", it throws
the "unexpected ;" error[/quote]

this line will put $update['id'] with null if it's not sent with post ...
the idea is to show error of it's not sent
if( $this->input->post('id') ) $update['id'] = $this->input->post('id');
else show_error('error: id must be set');


Can someone "translate" this in plain English to me, please? - El Forum - 01-02-2010

[eluser]developer10[/eluser]
thanks, i'm about to elaborate on this,

btw, i was trying to remember where in the user guide i saw this, but to no avail Smile

Thanks again!


Can someone "translate" this in plain English to me, please? - El Forum - 01-02-2010

[eluser]Colin Williams[/eluser]
Well, the CI user guide covers CodeIgniter, not the entirety of PHP.