Published in: PHP
foreach ($object as $key => $value) { echo "Key: $key; Value: $value<br>\n"; } Ej. (prevent sql injection): foreach ($_POST as $key => $value) { }
Comments
Subscribe to comments
You need to login to post a comment.
Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.
damarev on 11/22/06
1 person has marked this snippet as a favorite
Published in: PHP
foreach ($object as $key => $value) { echo "Key: $key; Value: $value<br>\n"; } Ej. (prevent sql injection): foreach ($_POST as $key => $value) { }
Subscribe to comments
You need to login to post a comment.
You could also do print_r($object);
Thanks !
:)
Tyler, that would print them to the page, but you'd have to somehow retrieve the output (probably by AJAX) and use a monster regex to manipulate them.
If you want the keys as an array, you can use getobjectvars($object) and array_keys($array). (And then you can get the values using $object->$key and $array[$key].)
Sorry, getobjectvars is supposed to have underscores.
Self-correction: print_r($var, true) would return the output to the program, rather than outputting it, but the monster regex would still be required to manipulate the data.
And it's
get_object_vars. (The underscores should show now.)