mardi 26 avril 2016

Using Include Files with PHP Associative Array

I have an event listing page in a wordpress plugin I mage that is showing a date with times for that date.It shows 14 days worth.

I’ve used an associated array to grab the server date and strip it down to a number. Each day has an include file associated with it.

I’m trying to get it to sort those dates and then include that file so it will show.

When use the following code, it works fine. Shows the key, date, value and name of the include for all the 14 days.

$compare = array($getshow1=>("day1.php"),$getshow2=>("day2.php"),$getshow3=> ("day3.php"),$getshow4=>("day4.php"),$getshow5=>("day5.php"),$getshow6=>("day6.php"),$getshow7=>("day7.php"),$getshow8=>("day8.php"),$getshow9=>("day9.php"),$getshow10=>("day10.php"),$getshow11=>("day11.php"),$getshow12=>("day12.php"),$getshow13=>("day13.php"),$getshow14=>("day14.php")); 

ksort($compare);

foreach($compare as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}

However when change it to the following sorth to try and use the includes, it works but for some reason only shows on about half of the 14.

ksort($compare);

foreach($compare as $x => $x_value) {
include $x_value;

}

I’m thinking there is some function I need to use but I’ve working on this a while now and think I have code block. Any help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire