Hai

I had an array in php that stores some integer ie $myArray=array(1,4,6,8,9); and I need to select the remaining integers from 1-30 other than the integers in the array. ie

my old array is $myArray=array(1,4,6,8,9); my new array is $newArray=array(2,3,5,7,10); Thanks in advance
Rajeesh

Hi,

To acheive what you're trying to do, use the following code...

$arr_original = array(1,3,5,7);
$arr_others = array(1,2,3,4,5,6,7,8,9,10);
$arr_diff = array_diff($arr_original, $arr_others);

So long as the second array contains all the numbers, it array_diff will return the difference.

R

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.