$headers=array(
$requestMethod." /rest/obj HTTP/1.1",
"listable-meta: ".$listablemeta,
"meta: ".$nonlistmeta,
'accept: */*',
);
In the above example, I’d like to omit the whole line if $listablemeta or $nonlistmeta is blank.
Assume $listablemeta is blank. Then the array would be:
$headers=array(
$requestMethod." /rest/obj HTTP/1.1",
"meta: ".$nonlistmeta,
'accept: */*',
);
Now I can setup a conditional isempty() and set the array accordingly, but what if I want to construct an array with say 20 different values each only setting if the variable on each line is not empty, is there another way to set a conditional -within- an array declaration? If not, what is another way to approach this problem?
Thanks!
You can’t do any conditionals inside the array clause that would help you with this, but this should suit your needs:
If the headers you want to pass to the array are as follows:
Build a key/value array of these variables:
Note that if the value doesn’t have a key as in
requestMethod, just put a numeric value there. Then loop them through and build the final array:$headersshould now contain something like this: