I'm very new to PHP so please go easy on me. This problem has had me bemused for a couple of hours now so I thought I would swallow my pride and come to you guys in hope that you can see why this could be a problem.
I have an array which I have converted from an object array with the following code:
$category_tree = $client->catalogCategoryTree($session_id); // Get an object array of all categories and assign to $category_tree.
$category_list = (array) $category_tree; // Convert $category_tree into an array and assign to $category_list.
This outputs as the following when using print_r($category_list):
Array
(
[category_id] => 1
[parent_id] => 0
[name] => Root Catalog
[position] => 0
[level] => 0
[children] => Array
(
[0] => stdClass Object
(
[category_id] => 2
[parent_id] => 1
[name] => Root Category
[is_active] => 1
[position] => 1
[level] => 1
[children] => Array
(
[0] => stdClass Object
(
[category_id] => 8
[parent_id] => 2
[name] => Designer
[is_active] => 1
[position] => 1
[level] => 2
[children] => Array
(
)
)
[1] => stdClass Object
(
[category_id] => 7
[parent_id] => 2
[name] => Shop Bags
[is_active] => 1
[position] => 2
[level] => 2
[children] => Array
(
)
)
[2] => stdClass Object
(
[category_id] => 5
[parent_id] => 2
[name] => DifferentCategory
[is_active] => 1
[position] => 3
[level] => 2
[children] => Array
(
[0] => stdClass Object
(
[category_id] => 6
[parent_id] => 5
[name] => 1
[is_active] => 1
[position] => 1
[level] => 3
[children] => Array
(
)
)
)
)
[3] => stdClass Object
(
[category_id] => 4
[parent_id] => 2
[name] => Sample Category
[is_active] => 1
[position] => 6
[level] => 2
[children] => Array
(
)
)
)
)
)
)
When I am testing for if a string exists within this array using in_array(), the result is telling me that it does exist within the string, despite it not doing. Please see the code below for this:
$string = 'Chanel';
if (in_array($string, $category_list)) {
echo 'The string is in the array';
} else {
echo 'The string is not in the array';
}
This outputs:
The string is in the array
But it isn't (as you can see from the array output above).
Thank you in advance for any insight you can offer this new guy :)
'string == 0'