it might be a stupid question but I am failing to combine some elseifs. I’m sure there must be smarter way. Do you have an idea?
<?php
$level_ids = leaky_paywall_subscriber_current_level_ids();
if (!empty($level_ids)) {
if (in_array(2, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(3, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(4, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(6, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(7, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(9, $level_ids)) {
echo 'DO THIS';
}
elseif (in_array(10, $level_ids)) {
echo 'DO THIS';
}
else {
echo 'DO THAT';
}
}
?>
I tried to combine that much smarter but it doesn’t work.
Thank yopu so much for helping put!
3
Answers
Define an array of what each should do,like this!
Try it out here https://3v4l.org/KBDRJ
There is nothing wrong with the way you wrote it. I would have formatted the code slightly differently according to the One True Brace Style, but that’s because I’ve been around forever: