php - How do i shorten a if statement in that situation? -
i'm doing if statement check if value in array
if ((!in_array($add['job_type'][$key], $jobtypes))) { $add['job_type'][$key] = null; } i did multiple if statements same thing, want this, put code smaller , easy read:
$value = ($value == '0') ? $value = null : $value; how can that?
i don't think length of if statement problem if code unreadable. suspect it's because:
i did multiple if statements same thing
instead of manually specifying multiple if statements, can make function:
function updatejobtype($key) { if ((!in_array($add['job_type'][$key], $jobtypes))) { $add['job_type'][$key] = null; } } then invoke whichever arguments like:
updatejobtype('job1'); updatejobtype('job2'); updatejobtype('job3'); that said, it's bit hard tell without full context of problem, or full code.
Comments
Post a Comment