/ Published in: PHP
Expand |
Embed | Plain Text
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.

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.)