0

the following produces no output, when really it should show a list including Milk, Cheese and Yoghurt. It is probably something really simple, I just can't see it.

 <?php 

 $FoodList=array();
 $newArray =array();
 echo "<p>";


 $Dairy= array(
    'a' => 'Milk',
    'b' => 'Cheese',
    'c' => 'Yoghurt',
 );
 $Fruit = array(
    'd' => 'Apples',
    'e' => 'Oranges',
    'f' => 'Grapefruit',
 );
 $GlutenFree = array(
    'g' => 'GF Cookies',
    'h' => 'GF Pancakes',
    'i' => 'GF Bread',
 );
 $Sweets = array(
    'j' => 'Musk Sticks',
    'k' => 'Caramels',
    'l' => 'Chocolate',
 );


 if ($_POST['running'] == 'yes')
 {
    $newArray = array_merge($FoodList, $Dairy);

    foreach ($newArray as $key => $value)
    {
       echo $value;
    }
 }


 echo "<p>";
 ?>

This may because the FoodList Array does not have anything in it, so I will look into that, but I have a strong feeling it is related to something else.

3
  • 1
    What is in $newArray? Use print_r( $newArray ) to see what's in it. Commented Sep 7, 2013 at 3:48
  • 1
    @AndyLester $newArray is an empty array. Also I've tried your code and it works perfectly. Maybe the $_POST['running'] !== 'yes'? Commented Sep 7, 2013 at 3:50
  • 1
    Actually, your handler should contain $Running=$_POST['Running']; then you should be checking if it's true meaning if it has been checked if ($_POST['Running'] == true) and your input should be <input type="checkbox" name="Running" /> so when it's checked, it will return MilkCheeseYoghurt and nothing if it isn't checked. Commented Sep 7, 2013 at 4:04

2 Answers 2

1

Your "bug" must be coming from the line, the array merge is fine:

 if ($_POST['running'] == 'yes')
Sign up to request clarification or add additional context in comments.

4 Comments

The HTML page states: Running <input type="checkbox" name="Running" value="Yes" />
I have changed 'running' to 'Running' but it still produces no output
'running' !== 'Running'
@AndrewSmith In the future, post all relevant code in your question. One of the most important factors (50%) are form elements which were not posted in your question.
0

foreach($Dairy as $key => $value) {

echo $value; }

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.