I have recently started learning PHPCPP - A C++ library for developing PHP extensions and trying to understand:
- how to pass an Array of objects from php to C++ through PHPCPP library as examples give only info about arrays and objects separately,
- then how to loop through each object in C++
- and how to return an associative array back to PHP
Can someone point me to the right direction?
I have come up with this example however need some help:
class Curve{
public :
double shape;
double peak;
double tpeak;
double start;
double lag;
double index;
};
Php::Value example1(Php::Parameters ¶ms) {
vector<Curve> c = params[0];
//create an associative array and return to php
std::map< std::string, std::map<std::string, std::map<std::string, std::map<std::string, std::double>>> > data;
// loop through array of objects here or do something with an array
...
data[c.shape][c.peak][c.tpeak][c.start] = 1/12 * c.index;
return data;
}
extern "C" {
PHPCPP_EXPORT void *get_module() {
static Php::Extension myExtension("my_extension", "1.0");
myExtension.add<example1>("example1", {
Php::ByVal("curves", "Array", false);
});
eturn myExtension;
}
}