Jump to content

Recommended Posts

I have:

<?php

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

echo "<strong class='textb'>$key : $value <br /></strong>";

}

?>

 

I need something that will dump the arrays submitted along with it.

 

To see it run simply submit something within one of the forms (note: roof is complete).

How many dimensions are you expecting to have?

 

If a bunch you want to look into recursion, if not this would work:

 

<?php
foreach( $_POST as $key => $value){
    if (is_array($value)) {
           foreach ($value as $k => $v) {
                echo "  <strong class='textb'>$k : $v <br /></strong>";
           }
    }else {
        echo "<strong class='textb'>$key : $value <br /></strong>";
   }
}
?>

first version:

<?php

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

    if (is_array($value)) {

          foreach ($value as $k => $v) {

                echo "  <strong class='textb'>$k : $v <br /></strong>";

          }

    }else {

        echo "<strong class='textb'>$key : $value <br /></strong>";

  }

}

?>

<p></p>

Seccond version:

<?php

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

  echo "<strong class='textb'>$key :";

  print_r($value);

  echo "<br /></strong>";

}

?>

<?php
  function print_value ( $list ) {
    if(is_array($list)){
      print "<ul>";
      foreach($list as $k => $v){
        print "<li><b>{$k}:</b> ";
        print_value($v);
        print "</li>";
      }
      print "</ul>";
    }else{
      print $list;
    }
  }
  print_value($_POST);
?>

are the names of the checkboxes all the same? like this:

<input type="checkbox" name="foobar" value="check1" />Check 1
<input type="checkbox" name="foobar" value="check2" />Check 2
<input type="checkbox" name="foobar" value="check3" />Check 3

if so, that is your problem...it needs to be:

<input type="checkbox" name="foobar[]" value="check1" />Check 1
<input type="checkbox" name="foobar[]" value="check2" />Check 2
<input type="checkbox" name="foobar[]" value="check3" />Check 3

 

I guess I need a tiny bot more help.

 

  function print_value ( $list, $project ) {
    if(is_array($list)){
      $project="$project <ul>";
      foreach($list as $k => $v){
        $project="$project <li><b>{$k}:</b> ";
        print_value($v, $project);
        $project= "$project </li>";
      }
      $project= "$project </ul>";
    }else{
      $project= "$project $list";
    }
  }
  print_value($_POST, $project);
echo "project: $project";

I guess I need a tiny bot more help.

 

  function print_value ( $list, $project ) {
    if(is_array($list)){
      $project="$project <ul>";
      foreach($list as $k => $v){
        $project="$project <li><b>{$k}:</b> ";
        print_value($v, $project);
        $project= "$project </li>";
      }
      $project= "$project </ul>";
    }else{
      $project= "$project $list";
    }
  }
  print_value($_POST, $project);
echo "project: $project";

 

what are you trying to do? cus you keep rewriting the variable $project

are you trying to do this:

<?php
  function make_list ( $list ) {
    if(is_array($list)){
      $rval =  "<ul>";
      foreach($list as $k => $v){
        $rval .= "<li><b>{$k}:</b> " . make_list($v) . "</li>";
      }
      $rval .= "</ul>";
    }else{
      $rval .= $list;
    }
    return $rval;
  }
  $project = make_list($_POST);
  echo "project: $project";
?>

??

I just realized that I needed to add another feature, since it's dumping project into itself for the required fields.

 

Example:

  function make_list ( $list ) {

    if(is_array($list)){

      $rval =  "<ul>";

      foreach($list as $k => $v){

        if ($k!=project){

        $rval .= "<li><b>{$k}:</b> " . mysql_real_escape_string(make_list($v)) . "</li>";

        }

      }

      $rval .= "</ul>";

    }else{

      $rval .= "$list <br> $project";

    }

    return $rval;

  }

  $project = make_list($_POST);

  echo "project: $project";

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.