Jump to content

getting rid of null values


dj262501

Recommended Posts

I have a php page where user/db info is being passed:

 

<?php
include "include/dbc.php";

include "include/header.inc";

$exerciseid = $_POST["exerciseid"];
$duration = $_POST["duration"];
$distance = $_POST["distance"];
$metric = $_POST["metric"];

echo'<h1>Added Activities</h1>';



// name of array
echo '<h1>Exercise</h1>';
if (is_array($exerciseid)) {
        foreach ($exerciseid as $key => $value) {

        echo $key .' : '. $value .'<br />';

        }
}



// name of array
echo '<h1>Duration</h1>';
if (is_array($duration)) {
        foreach ($duration as $key => $value) {

                        echo $key .' : '. $value .'<br />';

        }
}


// name of array
echo '<h1>Distance</h1>';
if (is_array($distance)) {
        foreach ($distance as $key => $value) {

                        echo $key .' : '. $value .'<br />';

        }
}

// name of array
echo '<h1>Metric</h1>';
if (is_array($metric)) {
        foreach ($metric as $key => $value) {

                        echo $key .' : '. $value .'<br />';

        }
}

?>

 

And here is the output from that code:

 

Added Activities

 

Exercise

0 : Canoeing, on camping trip

1 : Canoeing, rowing, over 6 mph, vigorous effort

2 : Canoeing, rowing, crewing, competition

3 : Canoeing, rowing, light effort

4 : Canoeing, rowing, moderate effort

5 : Diving, springboard or platform

6 : Kayaking

7 : Sailing, boat/board, windsurfing, general

8 : Sailing, in competition

9 : Skiing, water

10 : Ski-mobiling, water

11 : Skin diving, scuba diving, general

12 : Snorkeling

13 : Surfing, body or board

14 : Swimming laps, freestyle, fast, vigorous effort

15 : Swimming laps, freestyle, light/moderate effort

16 : Swimming, backstroke, general

17 : Swimming, breaststroke, general

18 : Swimming, butterfly, general

19 : Swimming, leisurely, general

20 : Swimming, sidestroke, general

21 : Swimming, sychronized

22 : Swimming, treading water, fast/vigorous

23 : Swimming, treading water, moderate effort

24 : Water polo

25 : Water volleyball

26 : Whitewater rafting, kayaking, or canoeing

 

Duration

Canoeing, on camping trip : 20

Canoeing, rowing, over 6 mph, vigorous effort :

Canoeing, rowing, crewing, competition :

Canoeing, rowing, light effort :

Canoeing, rowing, moderate effort :

Diving, springboard or platform :

Kayaking :

Sailing, boat/board, windsurfing, general :

Sailing, in competition :

Skiing, water :

Ski-mobiling, water :

Skin diving, scuba diving, general :

Snorkeling :

Surfing, body or board :

Swimming laps, freestyle, fast, vigorous effort :

Swimming laps, freestyle, light/moderate effort :

Swimming, backstroke, general :

Swimming, breaststroke, general :

Swimming, butterfly, general :

Swimming, leisurely, general :

Swimming, sidestroke, general :

Swimming, sychronized :

Swimming, treading water, fast/vigorous :

Swimming, treading water, moderate effort :

Water polo :

Water volleyball :

Whitewater rafting, kayaking, or canoeing :

 

Distance

Canoeing, on camping trip : 20

Canoeing, rowing, over 6 mph, vigorous effort :

Canoeing, rowing, crewing, competition :

Canoeing, rowing, light effort :

Canoeing, rowing, moderate effort :

Diving, springboard or platform :

Kayaking :

Sailing, boat/board, windsurfing, general :

Sailing, in competition :

Skiing, water :

Ski-mobiling, water :

Skin diving, scuba diving, general :

Snorkeling :

Surfing, body or board :

Swimming laps, freestyle, fast, vigorous effort :

Swimming laps, freestyle, light/moderate effort :

Swimming, backstroke, general :

Swimming, breaststroke, general :

Swimming, butterfly, general :

Swimming, leisurely, general :

Swimming, sidestroke, general :

Swimming, sychronized :

Swimming, treading water, fast/vigorous :

Swimming, treading water, moderate effort :

Water polo :

Water volleyball :

Whitewater rafting, kayaking, or canoeing :

 

Metric

0 : mile

1 : mile

2 : mile

3 : mile

4 : mile

5 : mile

6 : mile

7 : mile

8 : mile

9 : mile

10 : mile

11 : mile

12 : mile

13 : mile

14 : mile

15 : mile

16 : mile

17 : mile

18 : mile

19 : mile

20 : mile

21 : mile

22 : mile

23 : mile

24 : mile

25 : mile

26 : mile

 

 

As you can see, null values are being passed as well. I am hoping that someone can show me the correct way to use php unset to get rid of these null values. Thank you.

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.