I would like to know how to avoid the OUTPUT of var_dump($abc); from showing in the output screen and instead use it to feed a variable. Well, I am trying to put the output of <form><select name="study_Class"><option value="word1 (space) word2">word1 word2</option></form> into php program as an array as shown below (as its multiple choices) and want to use the words seperated by space as in the <value> attribute. But don't want the output of var_dump($); showing in the screen. Is there a way? (Below is my code)

<form action="abc.php" method="post">
    <select name="study_class[]" multiple>
    <option value="Class 1">CLASS 1</option>
    <option value="Class 2">CLASS 2</option>
    <option value="Class 3">CLASS 1</option>
    <option value="Class 4">CLASS 2</option>
    </select>
    </form>
    abc.php
    <?php
    #get data
    $study_class=implode(', ', $_POST['study_class']);
    var_dump($study_class);
    ?>
    <html>
    .
    .
    <P> Study Classes Chosen are: <?php echo $study_class; ?></P>
    .
    </html>

So on top of the OUTPUT screen first the
string(31) Class 1, Class 2
comes.
Then my echo response comes:
Study Classes Chosen are: Class 1, Class2
HOW to avoid the string.....
Also I will be feeding the $study_class as output in mail.

Thanks.

Confused..

By using var_dump, it just dumps whatever is stored in a particular varialbe and then outputs it to the screen (or whatever)! In order to display the output, you should just use echo/printf?

<form action="abc.php" method="post">
    <select name="study_class[]" multiple>
    <option value="Class 1">CLASS 1</option>
    <option value="Class 2">CLASS 2</option>
    <option value="Class 3">CLASS 1</option>
    <option value="Class 4">CLASS 2</option>
    </select>
    </form>
    abc.php
    <?php
    #get data
    $study_class=implode(', ', $_POST['study_class']);
    //var_dump($study_class);
    echo $study_class; // this would output it.
    ?>
    <html>
    .
    .
    <P> Study Classes Chosen are: <?php echo $study_class; ?></P>
    .
    </html>

I don't know if that's what you mean! Or whether you want to actually store the result of var_dump inside a variable.

commented: understood question better +5

$myvar = var_dump($study_class);?

to have better control use foreach()

foreach($_POST['study_class'] as $key=>$value){//for each variable in the array $study_class
    //do the following ($key == the key of this array entry, $value == value of entry in array)
    echo $value."<br/>\r\n";
}

$key will just be 0,1,2,3 etc in your code though

Phorce...thanks for the UnConfusion..
i have done away with var_dump($study_class); and i am getting output as desired 'word (space) word' eg. 'Class 1'. I thought output will neglect characters after space.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.