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

Unable to open serial port using Putty to bluetooth device on windows 7 64 bit -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -