php switch case error

i having an error came out each time i echo this on my index.php

below is my switch code, as i’m using php dynamic site hence i use switch to change the data each time when different php is call.

function title_switch()
$var = (isset($_GET[‘page’]) && !empty($_GET[‘page’])) ? $_GET[‘page’] : ‘home’;
switch ($var) {
case ‘home’:
$a[‘title’] = " » Home";
$a[‘meta_d’] = “This page is about my site!”;
$a[‘meta_k’] = “something, somethingelse”;
$a[‘slider1’] = “<script type=“text/javascript” src=”./js/jquery.easing.1.3.js">\n";
$a[‘slider2’] = “<script type=“text/javascript” src=”./js/tms-0.3.js">\n";
$a[‘slider3’] = “<script type=“text/javascript” src=”./js/tms_presets.js">\n";
$a[‘main’] = “<script type=“text/javascript” src=”./js/script.js">\n";
$a[‘pageid’] = “page1”;
$a[‘slider’] = “slide”;
case ‘company’:
$a[‘title’] = " » Company";
$a[‘meta_d’] = “This page is about my site!”;
$a[‘meta_k’] = “something, somethingelse”;
$a[‘all’] = “<script type=“text/javascript” src=”./js/all.js">\n";
$a[‘pageid’] = “page2”;
$a[‘slider’] = “banner”;
$a[‘title’] = " » HTTP 404 - Page Not Found";
$a[‘meta_d’] = “”;
$a[‘meta_k’] = “”;
return $a;
$details = title_switch();
?> [/php]

this is my index.php on line 21

[php]<?php echo $details['all']; ?>[/php]

if go to it will show below error

[code] Notice: Undefined index: all in C:\wamp\www\site\index.php on line 21 Call Stack
Time Memory Function Location

1 0.0035 258968 {main}( ) ..\index.php:0[/code]

if i call it will not show any error…

may I know where did i went wrong? kinda confuse here…

example: if i call it didnt show error, but if i call it show error.

i wanted this code

[php]<?php echo $details['all']; ?>[/php]

to show only if and it will not show if is call.

the code inside:
[php]<?php echo $details['all']; ?>[/php]


[php]case ‘company’:
$a[‘title’] = " » Company";
$a[‘all’] = “<script type=“text/javascript” src=”./js/all.js">\n";[/php]

hope this can give a

You should define $a as an array and include a default value for every key expected to be in $details

For example

function title_switch() {
// define default/global values
$a = array(
‘title’ => ‘’,
‘all’ => ‘’,

$var = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 'home';
switch ($var) {


This way, if your switch fails, title_switch() will always return an array of default values.

I would agree with M@tt.

You are trying to access the $a[‘all’] variable - Key ‘all’ of the $a array.
This has been set if the Page you are viewing is Company, but not on any other - so you are getting the error - Undefined index ‘all’ as it hasnt’ been set.

Initiallising $a as an array and giving it default values for each key you intend to populate should help with this.


Sponsor our Newsletter | Privacy Policy | Terms of Service