From c56ace6f2b24f91c7ddb7ec88537dd3d77b9634a Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 16 Mar 2014 15:05:26 +0100 Subject: updated documentation about iterating --- documentation/variables.html | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'documentation') 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;

- @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. +

+

+


+/**
+ *  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;
+    }
+}
+
+

+

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

Objects

-- cgit v1.2.3