Php ternary operator expression help

problem description

A judgment about the data removes the value from the array if it is empty, and passes the MD5 encrypted character value to the value if it is not empty.

for example, an array of $data has $data ["pass"]. If $data [" pass"] is empty, unset () is dropped, and if it is not empty, $data ["pass"] = md5 ($data [" pass"]).

how can I use a ternary expression instead of if to judge? Ask for expert advice.

Mar.29,2021

has just been tested. Unset cannot be used in ternary expressions. Use if


honestly.

for example, a scenario, ha, is a scenario in which the password is changed when the user's information is changed.
use the original if you don't fill it in, then use the new one and encrypt it with hash

$data['password'] = !empty($data['password']) ? Hash::make($data['password']) : $row['password'];

this way determines that if the password is not empty, encrypt it, otherwise use the old password!

according to your needs
should be usable

Menu