How to update field value by content type Drupal

Here is the code to update field value by content type Drupal

$query = \Drupal::entityQuery('node')->condition('type', ' dealer_locator')->execute();
$nodes =  \Drupal\node\Entity\Node::loadMultiple($query);
foreach ($nodes as $node) {
$node  =  \Drupal\node\Entity\Node::load($node->nid->valued);
 $field_status=1;
$node->set('field_status',  $field_status);
 $node->save();
}

php stristr

php stristr is one of the most build in library function in PHP, it searches for the first occurrence of a string inside another string and returns the rest of the string from the matching string.

echo stristr(“Good Morning!”,”Morning”);

Output

Morning!

 

echo stristr(“Good Morning! Dear”,”Morning”);

Output

Morning! Dear

 

Return Value: Returns the rest of the string from the matching string.