I am trying to extract some checkboxes values into an array. My problem is array($is_types). I am expecting $is_types to be an array, say array(one, two, three):
<?php
if (!is_array($types)) {
$types = array();
}
$filtered_array = array_filter($types);
$is_types = in_array($type, $filtered_array);
$output = _get_array(array($is_types), $bla, $bla2);
?>
UPDATE:
I need to rephrase what I am trying to achieve.
I have some checkboxes with options: one, two, three, etc. Only when I check them, the options should be stored. Checking what are stored is enough with $is_types, returning the bool.
Then I have a need to do other queries to aggregate content based on these checked checkboxes. That is if I have an array(one, two, three), based on the filtered checkboxes, then run the query
UPDATE2:
function _get_array($type, $view_mode, $limit = NULL) {
$node = menu_get_object();
$build = array();
$query = new EntityFieldQuery();
$created = isset($node) ? $node->created : 'now';
$query
->entityCondition('entity_type', 'node')
->entityCondition('bundle', $type, is_array($type) ? 'IN' : '=')
->propertyCondition('status', 1)
->propertyOrderBy('created', 'DESC')
->propertyCondition('created', $created, '<');
if ($limit != NULL) {
$query->range(0, $limit);
}
$result = $query->execute();
if (!empty($result['node'])) {
$nodes = entity_load('node', array_keys($result['node']));
$build[] = node_view_multiple($nodes, $view_mode);
}
return !empty($build) ? $build : array();
}
The checkboxes are just checkboxes with some values.
So querying _get_array(array($is_types), $bla, $bla2); should load all nodes filtered by these checkboxes value.
Any hint would be very much appreciated. Thanks
UPDATE3:
Thanks to all. The answer was there all along. What I need seems just: $filtered_array
OK, I understand what you mean. You probably have the following HTML…
And on the server, you want an array containing one, two or three depending on which were selected.
Basically, you have to add square brackets to ‘test’ to tell PHP to consider
testas an array, like so:And on the server, you simply access this as follows:
Beware that if none of the options were selected, you won’t get an array. Instead, do the following:
To ensure all variables are legit, do the following: