How do I pass the value of a PHP variable?
In Drupal 8 drupal_add_css(), drupal_add_js() and drupal_add_library() have been removed, and we are supposed to use #attached.

$page['#attached']['library'][] = 'fluffiness/cuddly-slider';
$page['#attached']['drupalSettings']['fluffiness']['cuddlySlider']['foo'] = 'bar';


More details about how JavaScript can be added in Drupal 8 can be found in https://www.drupal.org/theme-guide/8/assets#configurable-javascript.