My Code snippet:

$data=mysql_query($query); 
while($arr = @mysql_fetch_assoc($data)){
$results[]=$arr;
}

if(@is_array($results[$i])){

print results[$i]['mysql_field1'];
print results[$i]['mysql_field2'];
print results[$i]['mysql_field3'];
print results[$i]['mysql_field4'];

$attn[]=array($results[$i]['mysql_field1']); // I only want to get all the elements from mysql_field1 into the $attn array

}

print_r($attn);

If I do the print_r I get all the elements but not in a very friendly format:

Array ( [0] => Array ( [0] => 32454 ) [1] => Array ( [0] => 23859 ) )

Does anyone how to display all these elements in a more elegant manner?

Thank you guys!!!

    I use

    print '<pre>'.print_r($attn,true).'</pre>';
    

    to preserve the white space.

      That did not help unfortunately :queasy:

      All it did was to display it like this:

      Array
      (
          [0] => Array
              (
                  [0] => 32454
              )
      
      [1] => Array
          (
              [0] => 23859
          )
      
      )
      
      

      What I wanted is to display the array values only without their position within the array.

        Oh, well, you had asked for a friendlier format and I like that one. For what you're saying now, try this:

        foreach ($attn as $sub_array) {
          foreach($sub_array as $a_value) {
            echo $a_value."\n<br />\n";
          }
        }
        

          Thank you guys. You rock as usual!
          I should really get into learning using this nifty foreach() function. It's kind of a pain for me to grasp momentarily but maybe with some tutorials...

            Keep in mind that print_r() is more for debugging purposes than generating output. The problem is that when someone wants something "friendlier" there's pretty much a different value of "friendly" for everyone asking.

            As a consequence, if you want something friendlier, you have to do some programming. Which means learning the language. (For examples of the use of the [man]foreach[/man] construct, see that page).

              Write a Reply...