I use DomCrawler to grab some data, and I would like to know if I can get an array from a closure, here is my code :
$promises = $products
->each(function(Crawler $node) use ($client, $cookieJar) {
$href = $node->filter('a')->last()->attr('href');
return [
$href => $client->getAsync($this->config['url'] . $href, [
'cookies' => $cookieJar,
])
];
});
It will return me like :
$promises = [
['href_value' => Guzzle\Promise],
....
];
But I would like to have :
$promises = [
'href_value' => Guzzle\Promise,
....
];
How can I tranform the return statetement to have this result, something like this in my mind :
return ($href) => $client->getAsync($this->config['url'] . $href, [
'cookies' => $cookieJar,
]);