Notice: Undefined offset: 1 error
In the code above $parent is an array so $parent-&gt;tid is illegal. I am not sure what you are trying to find in the $parent but you should also note that the parent array has numeric indicies. So you probably have to do it this wat $parent[45] or $parent[$city-&gt;tid] depending on your requirement