No, you'll have to map over the collection.
How to modify a value in a collection based on condition?
The question is simple, how do we modify an element in a collection? I have a collection of items and one key is for the picture. The picture data can be an external link or stored locally. So what I am doing is checking with this function if the picture data exists on the remote server:
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
What I need to do is, if the result is true it means that the picture exists remotely. If it's false it means it doesn't exist remotely. In this case I want to replace the name of the picture to a "image-not-found.png" which I store locally. The question is how do you modify that data without looping? Is it possible?
Please or to participate in this conversation.