[Solved] Check if array has [0][1][2] or just single item
[ad_1] You can test whether CustomCategory contains is an indexed or associative array by checking for an element with index 0. If not, you can wrap the contents in an array and then do your foreach loop. $customCategory = $obj[“Store”][“CustomCategories”][“CustomCategory”]; if (!$customCategory[0]) { $customCategory = array($customCategory); } foreach ($customCategory as $category => $val) { … … Read more