您好我有一个使用此函数从XML文件创建的数组。删除数组中的重复项
# LOCATIONS XML HANDLER
#creates array holding values of field selected from XML string $xml
# @param string $xml
# @parm string $field_selection
# return array
#
function locations_xml_handler($xml,$field_selection){
# Init return array
$return = array();
# Load XML file into SimpleXML object
$xml_obj = simplexml_load_string($xml);
# Loop through each location and add data
foreach($xml_obj->LocationsData[0]->Location as $location){
$return[] = array("Name" =>$location ->$field_selection,);
}
# Return array of locations
return $return;
}
我该如何停止获取重复值或从数组中删除一旦创建?
为什么你做一个二维数组?你可以做'$ return [] = $ location - > $ field_selection'。 – Midas 2011-06-04 17:01:48