I am trying to print the results of this code:

$cmpResult = array_intersect($productList2, $totalProductList);
print_r("cmpResult:"); ?><br /><?php
print_r($cmpResult); ?><br /><?php

but the output is "Array ( )". How do I get it to output the values of the intersect?

Recommended Answers

All 3 Replies

foreach($cmpResult as $cmpResult)
print_r($cmpResult);

The above code should work

also post what you are getting as a result in
print_r($productList2) and print_r($totalProductList)

Member Avatar for rajarajan2017

Return result as we need:

<?php
$artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses');
$pasta = array('spaghetti', 'penne', 'Evanescence');
$cmpResult = array_intersect($artists, $pasta);
echo "<br/><br/>";
print_r("cmpResult:");
echo "<br/>";
print_r($cmpResult);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.