Skip to content
Advertisement

Determine if a property value is a blank string

So I have the following foreach inside my method as shown below:

foreach ($profiles as $profile) {
    $profile->load([
        'azure_picture' => Azure::init()->set_blob_sas_url
        ($profile->get_employee_id()),
        'azure_picture_expiration' =>
            $profile->set_azure_picture_expiration
            (strtotime('+7 days')),
    ]);
    $profile->save();
}

So 'azure_picture' => Azure::init()->set_blob_sas_url($profile->get_employee_id()), will return a string '' if the value is empty..

Is there a way that I can determine if azure_picture is an empty string, to pass in a empty string in 'azure_picture_expiration' => $profile->set_azure_picture_expiration(strtotime('+7 days')),..

So instead of passing strtotime('+7 days') automatically, I’d like to pass in an empty string if the azure_picture is empty, otherwise, use strtotime('+7 days').

All help would be appreciated!

Advertisement

Answer

foreach ($profiles as $profile) {
    $azure_picture = Azure::init()->set_blob_sas_url
    ($profile->get_employee_id());
    $profile->load([
        'azure_picture' => $azure_picture,
        'azure_picture_expiration' =>
            $profile->set_azure_picture_expiration
            ($azure_picture != '' ? strtotime('+7 days') : ''),
    ]);
    $profile->save();
}

Is this what you mean?

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement