3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = ['title' => 'The Title', 'type' => 'Movie', 'hour' => '', 'dayoftheweek' => 5, 'dayofthemonth' => '']; $whitelist = ['title' => '', 'type' => '']; $filtered = array_intersect_key($data, $whitelist); // var_export($filtered); // uncomment if you want to see what remains foreach($filtered as $key => $value) { echo "<div class=\"col-md-4\">\n"; echo "\t<div class=\"name-value\" id=\"$key\">$value</div>\n"; echo "</div>\n"; }
based on 8HqSe
Output for 5.6.38 - 5.6.40, 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.23, 7.4.0 - 7.4.11, 8.0.0alpha1 - rc2
<div class="col-md-4"> <div class="name-value" id="title">The Title</div> </div> <div class="col-md-4"> <div class="name-value" id="type">Movie</div> </div>