PHP array intersect question
Posted: Wed Mar 30, 2011 1:18 pm
I've two arrays, one which consist of constant values, the other which get filled dynamically. I am trying to find out if the dynamically filled array include any of the values inside the constant array, and which value is it exactly, so I've used the following code which is for some reason don't work as expected, as it returns null in some cases 
So can someone please help me and tell me what exactly I am doing wrong? Also is there a 'better' way to do it?
Thanks in advance for your time and efforts
NOTE: get_the_category and $category->cat_ID are two wordpress functions, which return the current category id and add it to the dynamic array
So can someone please help me and tell me what exactly I am doing wrong? Also is there a 'better' way to do it?
Thanks in advance for your time and efforts
NOTE: get_the_category and $category->cat_ID are two wordpress functions, which return the current category id and add it to the dynamic array
Code: Select all
<?php
unset($x);
unset($arr);
$x=array(4,3,7,1,31,43,38,63);
foreach((get_the_category()) as $category) {
$arr[] = $category->cat_ID ;
}
$result = array_intersect($x, $arr);
print_r($result);
?>