0

I populate a select box like this

foreach ( $prov->getLicences() as $licence ) {
    echo '<option value="' . $licence['id'] . '">' . $licence['licence'] . '</option>';
} 

This select box is for editing an existing db entry, so i can grab the already selected licences with this.

$prov->getSubscriberLicences($id)

This will return an array of id's, how do i check these id's against the available values in the select box above.

If they match i want to add the selected tag to the option value.

 echo '<option selected  value="' . $licence['id'] . '">' . $licence['licence'] . '</option>';

EDIT:

Please be aware $prov->getSubscriberLicences($id) returns an array of multiple ids here is a var dump

array(2) { [0]=> array(1) { ["id"]=> string(1) "1" } [1]=> array(1) { ["id"]=> string(1) "3" } }

looks like its multidementional

1

1 Answer 1

1

As very minimum info is given i can think of this only, Just try this-

$selected = (in_array($licence['id'],$prov->getSubscriberLicences($id)) ? "select" : "");

echo '<option '.$selected.'  value="' . $licence['id'] . '">' . $licence['licence'] . '</option>';
Sign up to request clarification or add additional context in comments.

3 Comments

on which line your are getting?
@VinceLowe: my bad, updated first line, did not close the bracket.
i spotted it, still non are showing as selected.. is it because $licence['id'] is a value and not array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.