0

I am wondering how to put a foreach inside of an array. I've tried the following

$service_url = 'http://api.XXXXXXX/addData';
$curl = curl_init($service_url);               
$curl_post_data = array(              
    foreach ($additional_fields as $name => $value) {
        if (!empty($value)) {                     
            '$name' => $value,
        }                  
);            

but its giving me the error unexpected T_foreach.

Any ideas?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Scotty Boy
  • 147
  • 1
  • 3
  • 9
  • You can't have a *statement* inside an *expression*. You probably just need `$curl_post_data = array_filter($additional_fields)` though. – deceze Mar 15 '18 at 16:55
  • 2
    `how to put a foreach inside of an array` - you don't/can't. – kscherrer Mar 15 '18 at 16:55

0 Answers0