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

Vince Lowe
  • 3,521
  • 7
  • 36
  • 63
  • possible duplicate of [PHP multi dimensional array search](http://stackoverflow.com/questions/6661530/php-multi-dimensional-array-search) – Marc B Jan 11 '13 at 16:03

1 Answers1

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>';
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90