Skip to content →

Tag: short function

CakePHP: Ternary condition

Kalau selalu guna if and else, langkah seterusnya mesti tahu ternary condition. ade alternative lain nak guna dalam CakePHP, contoh:

/* ife in cakePHP */ ife($condition, $true, $false)

jadi, kalau statement ternary tu cam ni:

/* ternary condition */ echo ($x)?'x = true':'x = false';

ble ubah jadi macma ni. mudah sket

/* replace ternary with ife in cakePHP */ echo ife($x, 'x = true', 'x = false');

urm.. dapat?

Leave a Comment