您好我有一個使用此函數從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