I have an array that consists of many stdClasses after doing a json_decode on a json string.
It looks like this:
product: array(3)
0: stdClass
PropertyAbc: "Product 1|Product 5"
1: stdClass
PropertyXyz: "Product 2|Product 9|Product 10"
2: stdClass
PropertyEfg: "Product 3|Product 12"
I need to turn this into a pipe delimited string of all values in the following format: PropertyName>Value as my end result:
PropertyAbc>Product 1|PropertyAbc>Product 5|PropertyXyz>Product 2|PropertyXyz>Product 9|PropertyXyz>Product 10|PropertyEfg>Product 3|PropertyEfg>Product 12
Here is how I attempted to do it, but cant figure out how to get the value and name of the first property when looping through the stdClasses (note: there will always be only one property for each stdClass):
foreach ($json->products as $product) {
// Put all products in an array
$arr = explode('|', $NEED-VALUE-OF-FIRST-PROP);
// Loop through array and combine values
foreach ($arr as $key => $value) {
$arr[$key] = $NEED-NAME-OF-FIRST-PROP . ">" . $value;
}
}