we need to list an array sorting by an object value.
We have a list of films, sorted by alphabetical order, but we want to sort by genres.
here is the code listing in alphabetical order.
<?php
foreach ($films as $film_id => $film) {
echo "<ul>";
echo '<li id="film_thumb">';
echo '<a href="watch.php?id=' . $film_id . '" alt="ID">';
echo '<img class="thumb_res" src=" ' . $film["thumb"] . '" alt="' . $film["name"] . '">' ;
echo '</a>';
echo '</li>';
echo "</ul>";
} ?>
the function listing in alphabetical order is in the array file
sort($films, SORT_FLAG_CASE);
Here is the array
$films = array ();
$films[1] = array(
"name" => "21 Jump Street",
"year" => "2012",
"genre" => "Commedia",
"path" => "media/01.mp4",
"thumb"=> "media/thumb/01.png",
);
now, we need to create a page that list these items ( film thumb ) in categories, so if i click on genre "Action", the page must to show only selected film genre, and not the others.
Many thanks, Andrea
array_filter()to filter array by some value