summaryrefslogtreecommitdiff
path: root/documentation
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-16 15:05:26 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-16 15:05:26 +0100
commitc56ace6f2b24f91c7ddb7ec88537dd3d77b9634a (patch)
tree0943de1ff200ceb3f756bc747030951cd038d954 /documentation
parentec6d84016bec41b05e275641f990831572171969 (diff)
updated documentation about iterating
Diffstat (limited to 'documentation')
-rw-r--r--documentation/variables.html27
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 &amp;value)
+{
+ // assum the value variable holds an array or object, it then
+ // is possible to iterator over the values or properties
+ for (auto &amp;iter : value)
+ {
+ // output key and value
+ std::cout &lt;&lt; iter.first &lt;&lt; ": " &lt;&lt; iter.second &lt;&lt; std::endl;
+ }
+}
+</code></pre>
+</p>
+<p>
+ The iterator treats the values in the Value class as variables of type
+ std::pair&lt;Php::Value,Php::Value&gt;. You can thus access the 'first'
+ and 'second' properties to retrieve either the key or the value.
</p>
<h2 id="objects">Objects</h2>
<p>