adg63
New Member
Posts: 1
|
Post by adg63 on Sept 12, 2012 19:51:47 GMT -5
So does anyone know how to make the print_r or var dump look a little bit nicer? I have been looking around, but the best I got is in the screen shot I attached. And here is the code
echo "<pre>", "Here are the days of the week from an array: ", htmlspecialchars(print_r($daysoftheweek, true)), " </pre>\n";
Any help will be appreciated. Thanks guys
|
|
zjh7
New Member
Posts: 15
|
Post by zjh7 on Sept 13, 2012 12:09:03 GMT -5
An easier way to print the contents of an array might be a foreach loop:
foreach ($array as $newvar) { echo "$newvar"; }
This will take each item in the array $array, cast it into the new variable $newvar, and print them. If you want a space, you can make it "$newvar\n"
|
|
|
Post by fsilvestre on Sept 15, 2012 9:24:58 GMT -5
You don't need to do the $key=>$value with the foreach? For some reason I couldn't get it working without it. I'm just curious.
foreach ($array as $key => $value) { //do stuff }
|
|
kmt51
New Member
Posts: 11
|
Post by kmt51 on Sept 17, 2012 17:45:49 GMT -5
I came up with a similar result as ZJH7, good to have it verified. but the easiest method seems to be writing a foreach loop and just using a single variable instead of a $key => $value combo.
foreach ($arrayname as $value) { echo $value." "; }
that is, if your array has index's that are real words instead of numbers. otherwise you could iterate through it using those for indexes.
|
|