Thursday, 15 March 2012

show only values in my second array php -



show only values in my second array php -

i have 2 arrays comparing. comparing working follows:

$tmp = array_diff_key($arr1, $arr2); $echo $tmp;

however, want display values exist in array 2 don't exist in array 1.

edit: ok give thanks everyone's help. how ever still unable create work.

i using

$tmp = array_diff($arr2, $arr1); var_dump($tmp);

which prints out following:

array(1) { [0]=> array(3) { [0]=> string(4) "cars" [1]=> string(4) "vans" [2]=> string(6) "people" } }

so, i'll explain little.

array 1 has cars, vans (this pulled database).

array 2 has cars, people (this entered form).

i'm trying show values not in database thought $tmp echo people cars in database , vans in $arr1

i hope thats clear confusing me writing ;)

if var_dump both array individually get

array(3) { [0]=> null [1]=> string(4) "cars" [2]=> string(4) "vans" } array(1) { [0]=> array(2) { [0]=> string(6) "people" [1]=> string(5) "tanks" } }

$tmp = array_diff_key($arr2, $arr1); $echo $tmp;

echo $tmp output 'array' think, have loop on (perhaps foreach) display each individual value, or utilize var_dump.

array_diff_key works keys, array_diff values (you mention "values" in question).

php arrays

No comments:

Post a Comment