Jump to content

how to merge rotating codes in one using array


artist19

Recommended Posts

How do you write a code that merges these similar multiple codes into one? E.g.

 

<?php
$content = array( 
1 => "dir/filename.php", 
2 => "other.php", 
3 => "andso/on.php",

); 

$day = date('W'); 
$file = isset($content[$day]) ? $content[$day] : 'notes.php'; 
include $file;
?>

 

The main page uses an include (the code above) for the content part.

 

<?php

$sidebar = array(

1 => "dir/filename/sidebar.php",

2 => "other-sidebar.php",

3 => "andson/sidebar.php",

 

);

 

$day = date('W');

$file = isset($sidebar[$day]) ? $sidebar[$day] : 'notes.php';

include $file;

?>

 

The main page uses an include for the sidebar part.

 

<?php
$title = array( 
1 => "title of filename", 
2 => "other title", 
3 => "and so on",

); 
$day = date('W'); 
[not sure how to code this line]
echo $title;
?> 

 

Rather than repeating the same, how do you code three together in an array?

 

For example, CONCEPT below:

 

<?php // code above header
$rotate = array( 
1 => "dir/filename.php", "sidebar/file.php", "title here"
2 => "other.php", "sidebar/anotherfile.php", "title here"
3 => "andso/on.php", "sidebar/antoher.php, "title here"

$day = date('W'); 
$file = isset($content[$day]) ? $content[$day] : 'ls.php'; 
$sidebar = isset($content[$day]) ? $content[$day] : 'j.php'; 
$title = isset($title[$day]) ? $title[$day] : 'Title'; 
?>

<? // place an include in the main page
include $file;
?>

<? // place an include in the sidebar of the main page
include $sidebar; ?>

<? // place a title in the main page
echo $title; ?>

 

 

Thank you and greatly appreciated in advance.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.