Quick overview: trying to build a gallery with a string from $_GET (‘foo’), which was passed via AJAX and then generate a small list from that, with title and description.
Is it possible for an array to have 3 elements? In the foreach here it generates list items that use ‘foo’, and then a title and description follow, but I don’t know how to pick out the proper/associated title/description, the one that relates to ‘foo’. Below is what I have:
<?php function generateProject() {
$proj = $_GET['proj'];
$valid_proj = array("deadawesome", "chimaera", "manifesto");
if (!in_array($proj, $valid_proj)) {
}
echo '<div id="proj-wrapper">';
echo '<div id="proj">';
echo '<ul id="'.$proj.'">';
$imgs = glob("../images/portfolio/$proj/*.jpg");
foreach ($imgs as $picture) {
// Get only the base filename
$picture = basename($picture);
// Then build the <li>
echo '<li><a href="javascript:void(0);"><img src="../images/portfolio/'.$proj.'/'.$picture.'">';
echo '</li>';
}
echo '</ul>';
echo '</div>';
echo '</div>';
echo '<div class="description">'.$projTitle.' <span class="slash"> / </span>'.$projDesc.'</div>';
} ?>
<?php
generateProject();
?>
Would it be possible to make an array like this, and then find the one that matches ‘foo’ and give the following two values $projTitle and $projDesc?
$projTitles = array('foo' => 'FooTitle' => 'The description for Foo.',
'bar' => 'BarTitle' => 'The description for Bar.',
'presto' => 'PrestoTitle' => 'The description for Presto.'
);
You want an array of associative arrays:
You can then loop through it and access the attributes of each array element like so: