Trouble with checked() for array of multiple checkboxes
I can't get the checked() to return what I expect.
Data:
Options: = array (
'baseball' = 'Baseball',
'golf' = 'Golf',
'hockey' = 'Hockey',
)
Values: = array (
'baseball' = 'Baseball',
'golf' = '',
'hockey' = '',
)
I'm using this code to try to return 'checked="checked"'
foreach ( $options as $key = $title ) {
rpq_plugin_debug_var( $key, 'Key: ' );
rpq_plugin_debug_var( $title, 'Title: ' );
$checked = checked((in_array($key, $values)), true, false);
I'd expect the baseball option to return 'checked="checked"' but it returns ''.
I've also tried this, which actually makes more sense to me, with no success, either.
$checked = checked((in_array($title, $values)), true, false);
Where is my error?
Many thanks.
EDIT: See comments below this post for answer.
Make $values array not associative.
Values: = array ( 'baseball', 'golf' )
Use this line to identify checkmarks
$checked = checked((in_array($key, $values)), true, false);