P粉6158866602023-07-31 15:41:35
The problem is that $arrTree is a multidimensional array.
The foreach loop in your code only traverses the first level of the array, but does not traverse nested arrays (such as "grades"). When it encounters "grades" the value of $v is not a string but an array, that's why the is_string($v) check fails.
You need to add a nested foreach loop to handle this structure.
Here is an example showing how to achieve this:
foreach ($arrTree as $k => $v)
{
if (is_string($v))
{
//Do something here
}
else if (is_array($v))
{
foreach($v as $key => $value)
{
if(is_string($value))
{
//Do something here
}
else if(is_array($value))
{
foreach($value as $innerKey => $innerValue)
{
if(is_string($innerValue))
{
//Do something here
}
}
}
}
}
}