diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-16 15:05:26 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-16 15:05:26 +0100 |
commit | c56ace6f2b24f91c7ddb7ec88537dd3d77b9634a (patch) | |
tree | 0943de1ff200ceb3f756bc747030951cd038d954 /documentation | |
parent | ec6d84016bec41b05e275641f990831572171969 (diff) |
updated documentation about iterating
Diffstat (limited to 'documentation')
-rw-r--r-- | documentation/variables.html | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/documentation/variables.html b/documentation/variables.html index a5341c7..e85e64f 100644 --- a/documentation/variables.html +++ b/documentation/variables.html @@ -333,7 +333,32 @@ array1 = 100; </code></pre> </p> <p> - @todo explain how to iterate over arrays + The Php::Value class also implements the begin() and end() methods that + you many STL containers has too. As a consequence, you can iterate + over an array just like you would iterate over a std::map class. +</p> +<p> +<pre class="language-c++"><code> +/** + * Function that accepts an array as parameter + * @param array + */ +void myFunction(const Php::Value &value) +{ + // assum the value variable holds an array or object, it then + // is possible to iterator over the values or properties + for (auto &iter : value) + { + // output key and value + std::cout << iter.first << ": " << iter.second << std::endl; + } +} +</code></pre> +</p> +<p> + The iterator treats the values in the Value class as variables of type + std::pair<Php::Value,Php::Value>. You can thus access the 'first' + and 'second' properties to retrieve either the key or the value. </p> <h2 id="objects">Objects</h2> <p> |