0

My var_dump is returning this:

array(5) { 
    ["radioinput"]=> string(12) "sidebar-left" 
    ["option1"]=> int(0) 
    ["sometext"]=> string(0) "" 
    ["selectinput"]=> NULL 
    ["sometextarea"]=> string(0) "" 
}

I'm having problems acting on the "radioinput" array.

If it's "sidebar-left" I want it to echo:

<body class="sidebar-left">

If it's "sidebar-right" I want it to echo:

<body class="sidebar-left">

If it's "two-sidebars" I want it to echo:

<body class="two-sidebars">

If it's blank I want it to echo:

<body class="sidebar-left">

My questions is, how can I get my code to do this?

<?php 
if (radioinput('sidebar-left')) { 
    echo '<body class="sidebar-left">';
} elseif (radioinput('sidebar-right')) {
    echo '<body class="sidebar-right">';
} elseif (radioinput('two-sidebars')) {
    echo '<body class="two-sidebars">';
} else {
    echo '<body class="sidebar-left">';
}
?>
1
  • 2
    $x["radioinput"] is not an array. It is a string. It says so right there in the dump. And you didn't tell us what $x really is. What's wrong with basic == conditionals? Commented Nov 8, 2011 at 1:07

3 Answers 3

3

The way you are addressing your array isn't correct. I am assuming that the array is going to be called $data.

or replace $data with whatever you had on var_dump(...)

Then, you code would look like:

if ($data['radioinput'] == "sidebar-left"){
   echo '<body class="sidebar-left">';
}elseif ($data['radioinput'] == "sidebar-right"){
   echo '<body class="sidebar-right">';
}else{
   //otherwise
}

Edit: You can even simplify that down to:

if ($data['radioinput'] == "sidebar-right"){
   echo '<body class="sidebar-right">';
}else{
    echo '<body class="sidebar-left">';
}

Cheers :)

Sign up to request clarification or add additional context in comments.

Comments

0

Change this:

if (radioinput('sidebar-left')) { 

To this:

// This assumes you named the array as $array, this was not mentioned in OP
if ($array['radioinput'] == 'sidebar-left') { 

Comments

0
$class = $array['radioinput'] == 'sidebar-right' ? 'right' : 'left';
printf('<body class="sidebar-%s">', $class);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.