How to pass multiple target_id/values field using entity reference prepopulate? I read the documentation and saw that this is possible: node/add/page?field_bar=1,2,3

But how do you code this? I wanted to pass multiple target id, not just one.

I tried this code but this only passes 1 value which is the first field value.

&lt;?php
$l = l( t('Create Package'), 'node/add/package',   array('query' =&gt; array('field_product_food' =&gt;$node-&gt;field_product_food['und'][0]['target_id'])  ));
echo $l; 
?&gt;


I also tried using an array loop like this:

&lt;?php
$nids = array();
foreach ($node-&gt;field_product_food[$node-&gt;language] as $index =&gt; $item) {
$nids[] = $item['target_id'];
}
$l = l( t('Create Package'), 'node/add/package',   array('query' =&gt; array('field_product_food' =&gt;$nids)  ));
echo $l; 
?&gt;


but the result is not like the example from the documentation.

Can somebody help me? 

Thank you very much!
So if you want to create this link: node/add/page?field_bar=1,2,3

You need to put a comma between each nid, so implode() is what you want.

E.g.

$l = l( t('Create Package'), 'node/add/package',   array('query' =&gt; array('field_product_food' =&gt; implode(',', $nids))  ));