Provides an array of values to be used in the element's <option>
tags.
NOTE: Some methods use both the array's keys and values while others use only the values. For example datalist() uses only the values while select() uses both the values and keys as seen below.
Value | Use |
---|---|
array | the values to create options |
This demonstrates a method that requires only values.
$options = [
'Foo',
'Bar',
'Baz'
];
<option value="foo"/>
<option value="bar"/>
<option value="baz"/>
This demonstrates a method that requires a key/value pair.
$options = [
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz'
];
<option value="foo">Foo</option>
<option value="bar">Bar</option>
<option value="baz">Baz</option>
This demonstrates a method that requires a key/value pair in which only values are passed.
Note the values of the <option>
tags are the key's numeric value. There may be times when output like this is desirable,
however, most times this is not intended.
$options = [
'Foo',
'Bar',
'Baz'
];
<option value="0">Foo</option>
<option value="1">Bar</option>
<option value="2">Baz</option>