How to get a list of all the selected values ​for a field programmatically? How can I get a list of all the selected values ​​for a field?

For example I have a field called countries, and I want to get all countries selected for a certain node.

I need to have this list, because I want the region to be automatically selected in another field (regions), according to the chosen country.

Ex: I choose France in the countries, then automatically the European region is selected in regions

For now I can only copy the selected values ​​in the "countries" field, in the "regions" field, by doing this:

$node-&gt;field_regions = $node-&gt;field_countries;


Here is the result when I select France in the countries field :

Country: France

Regions: France


Edit: I tried with the function:field_get_items(), but all I get is an array:

$items = field_get_items('node', $node, 'field_countries', $node-&gt;language);


Something is wrong? I also tried with this but I get the same result...

$items = $node-&gt;field_countries[$node-&gt;language][0]
Because fields can have multiple values both of the methods you describe will return an array. Each of those array items will itself be an array, of all the possible columns for the field. In the case of text fields the only column you really need to worry about is the value column.

Assuming your particular field does not accept multiple values, or it does and you only want the first value, the following should work:

$items = field_get_items('node', $node, 'field_countries', $node-&gt;language);
$item = array_shift($items);
$value = $item['value'];


or

$value = $node-&gt;field_countries[$node-&gt;language][0]['value'];