Issue
I want the latest image at the top when I add a new image at Event Menu. I want it sort by desc not asc.
this is my PHP code:-
<div class="post-slider">
<h1 class="slider-title">Event</h1>
<?php foreach ($event as $key => $single): ?>
<img src="<?php echo BASE_URL."/assets/events/".$single['photo']; ?>" alt="Paris" style="width:60%;"> <br><br>
<?php endforeach; ?>
<!--footer is here point to footer.php-->
<?php include(ROOT_PATH . "/app/includes/footer.php"); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- Slick Carousel -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<!-- Custom script -->
<script src="assets/js/scripts.js"></script>
</body>
</html>
Solution
array_reverse() returns a new array. (See array_reverse().) So you either need to store the new array first or just use function within the declaration of your for loop.
<?php
$input = array('a', 'b', 'c');
foreach (array_reverse($input) as $value) {
echo $value."\n";
}
?>
your output will be.
c
b
a
so according to your code
<?php foreach (array_reverse($event) as $key => $single): ?>
<img src="<?php echo BASE_URL."/assets/events/".$single['photo']; ?>" alt="Paris" style="width:60%;"> <br><br>
<?php endforeach; ?>
Answered By - Aqib Javed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.