Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need some help with PHP array_unique. In my code below, it works on every result except Bangladesh, Pakistan, Egypt, and India. Furthermore, it puts a few countries out of order on the top of the list. Help?

$params = array();
$params['in'] = '?';
ini_set("soap.wsdl_cache_enabled", "0");    
$client = new SoapClient("http://apollov-dev.worlddata.com/WrapSystem/services/FactoriesWS?wsdl",array("trace" => 1, "exceptions" => 0));

$monitorResult=$client->allActiveMonitors($params);
$countryList=array();

foreach($monitorResult->response as &$country)
{

    $countryArray=array();


    if(isset($country->accreditedCountries))
    {
    if(strpos($country->accreditedCountries,", ")!== false)
    {
        $countryArray=explode(",",$country->accreditedCountries);
    }
    else
        {$countryArray[]=$country->accreditedCountries;}

        foreach($countryArray as $value)
        {
            if(in_array($value,$countryList)==false)
                {$countryList[]=$value;}
            else {}

        }
    }
    else {}
}



$newArray=$countryList;
asort($newArray);
array_unique($newArray);


foreach($newArray as $record)
{
    echo $record;

    echo "<br/>";
}
share|improve this question
    
array_unique is case sensitive, so if there are any case disparity, then it won't filter them. Try doing dome string normalising (i.e. strtolower / strtoupper) when setting your countries. –  RaggaMuffin-420 Jan 10 at 17:30
    
Show the data in $newArray, don't force us all to make a soap request to see what you're seeing –  Mark Baker Jan 10 at 17:30
1  
$newArray is the same as $countryList –  user2174028 Jan 10 at 17:32
    
@user2174028 - I can SEE that.... what I can't see is any actual data without actually doing the SOAP request –  Mark Baker Jan 10 at 17:40
    
Here go:Bangladesh Canada Egypt India Jordan Pakistan Argentina Bangladesh Bhutan Cambodia China Colombia Dominican Republic Egypt Germany Guatemala Honduras Hong Kong India Indonesia Malaysia Mauritius Mexico Pakistan Peru Philippines Poland Portugal Romania Singapore South Africa South Korea Spain Sri Lanka Taiwan Thailand Trinidad and Tobago Turkey USA Vietnam –  user2174028 Jan 10 at 17:42

1 Answer 1

$newArray = array_unique(array_map('trim',$newArray));

array_unique works fine. Its bug of soap-service: return some words with space before.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.