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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -