I am quite bad at php. I have a Multicheckbox that outputs an array this way:
Array
(
[value1] => true
[value2] => false
[value2] => false
[value4] => false
[value5] => true
[value6] => false
)
I would like to return an array with only the elements (values) that are true. Then I will apply this:
$list_of_true_values = explode(',', $array_i_am_looking_for);
return $list_of_true_values;
As in the end I want to return this: value1,value5.
Thanks’
As Rajat has said you can use the
array_keys()function. I’d also add that if you’re looking to get an output ofvalue1,value5, you shouldn’t useexplode(), but rather, it’s duel,implode().return implode(",", array_keys($array, true));Is all you need.
As per your comment, if you’d like to wrap the keys in single quotes:
This is called Anonymous (Lambda) Syntax.