foreach 数组循环并不总是在 Windows 上工作


foreach array loop does not always work on Windows

我遇到了这个非常奇怪的场景。PHP如下:

$complete_categories_list=array();
foreach ($modules_library_processed as $key=>$modules_categories_rendered) {
    foreach ($modules_categories_rendered['modulecategories'] as $module_category_key=>$module_category_values) {
        foreach ((array) $module_category_values as $module_key_inner=>$module_category_value) {
            $complete_categories_list[]=trim($module_category_value);
        }
    }
}

这在Unix/Linux本地主机中完美运行,在某些情况下可以在Windows本地主机中工作。但不是全部。问题是,在循环结束时,即使$complete_categories_list有一些数据,$modules_library_processed也是空的。 $modules_library_processed是一个非常大的数组,所以我不能在这里发布整个数据。我希望有人能阐明这一点。

更新:源是一个XML文件 simplexml_load_string($modules_xml_exported);我将其转换为数组。结果是 $modules_library_processed .

将结果print_r($module_category_values)到 SimpleXMLElement Object ((

但是我把它类型转换为数组。所以这应该有效吗?

我想我已经解决了问题 根本原因是脚本处理 SimpleXML,即使使用所有类型转换等,当脚本在 Windows 下运行时也不会播放。我最终重写了我的脚本,因此它不会输出任何 SimpleXML 元素,而是全部以数组/字符串格式输出。我希望这对某人有所帮助。谢谢。