Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some key concepts in PHP that will transfer to any templating language or framework
<style>
.student {
border: 1px solid black;
padding: 10px;
}
</style>
<?php
$stuff = [
[
"key" => "value",
"title" => "This is a really long title",
],
[
"key" => "value",
"title" => "short title",
],
];
function render_card($title, $key) {
echo "<article class='card'>";
echo "<h1>" . $title . "</h1>";
echo "<p>" . $key . "</p>";
echo "</article>";
}
render_card("thing", "other");
?>
<?php function render_better_card($item) { ?>
<article class='student'>
<h1><?=$item['title']?></h1>
</article>
<?php } ?>
<?php
foreach ($stuff as $thing) {
render_better_card($thing);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment