jeudi 9 avril 2015

PHP Include based on Array value

I have multiple php files named as following:



  • footer-01.php

  • footer-02.php

  • footer-03.php


and I have this array



<?php
$footer = array(
1 => "01" // Choose Between 01 to 03
);
?>


I would like to use the value on this array to build up a php include file like the one showing below. the basic idea here is that based on the reference value on this array, a different include syntax would be build.


This is what I came up with but php are showing errors:



<?php
foreach($footer as $key => $item)
{
if ($key <> '')
include '../includes/footer-' . $footer[$key] . '.php';
}
?>


Any ideas on how that can be done? Thanks for help ...


Aucun commentaire:

Enregistrer un commentaire