In my function, in order to accept an array of values I have to define a data type…
myFunc( String[] myVar ) {}
What if I wanted an array like the below array that mixes objects and strings and nested arrays/ (Note: the below array is in PHP)
myFunc(array(
array(
'name' => 'Category1',
'products' => array(
array(
productObject,
productObject,
...
)
)
)
));
Is this possible in Java or is this a completely wrong technique?
You would need to use an object-oriented approach in Java (which will also work in PHP). The class structure for the object you’ve listed above would be as follows:
Then you can get an instance of that class by doing the following:
You can also have an array of this object type: