I have the following code.. and I know it's probably all wrong, but I haven't dealt with foreach loops before.
$last_names = regapiGetLastNames( NULL, -1 );
foreach ($last_names as $name => $last_name_id)
$exclude = array('11196','11195','11198','11197');
if(!in_array($name->last_name_id, $exclude)):
print '<option value="'.$last_name_id.'">'.$name.'</option>';
Obviously its going wrong somewhere, any help pls?
If the IDs are array values, then you can also use array_diff
to filter them:
$last_names = regapiGetLastNames( NULL, -1 );
$exclude = array('11196','11195','11198','11197');
$last_names = array_diff($last_names, $exclude);
foreach ($last_names as $name => $last_name_id) {
print '<option value="'.$last_name_id.'">'.$name.'</option>';
}
$last_names = regapiGetLastNames( NULL, -1 );
$exclude = array('11196','11195','11198','11197');
foreach ($last_names as $name => $last_name_id)
{
if(!in_array($name->last_name_id, $exclude))
print '<option value="'.$last_name_id.'">'.$name.'</option>';
}
You need the braces for a multiline loop. also, move the array declaration outside the loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With