xml - PHP - issue with array_count_values method -


the skuarray being populated values xml file, using simplexml_load_file method , first foreach loop below:

$xmlproducts = simplexml_load_file("products.xml"); $skuarray = array(); foreach($xmlproducts->product $product) { $skuarray[] = (string)$product->sku;  // product->sku contains sku value obtained xml file } 

in case, values inserted skuarray (5, 7, 3, 7, 1, 5, 7).

after array populated, check see if duplicate values exist in skuarray using array_count_values method. if so, if statement executes code.

$multiplesku = array_count_values($skuarray); 

the if statement in foreach loop not executing code, when multiple values exist in array (5 , 7 in array multiple times).

foreach($xmlproducts->product $product) {       if ($multiplesku[$product->sku] > 1) {     echo $product->sku;   } } 

the code looks written correctly! advice? thanks!

try

foreach($xmlproducts->product $product) {    $sku = (string) $product->sku;   if ($multiplesku[$sku] > 1) {     echo $product->sku;   } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -