1.array_diff()

add_action(‘init’, ‘fixing’);
function fixing(){

$mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);

$arr1 = array(“a” => “Cat”,”b” => “Dog”, “c” => “Horse”);
extract($arr1);
echo”\$a = $a; \$b = $b; \$c = $c”;
pre($arr1);
global $wpdb;
$result=$mysqli->query(“SELECT * from wp_posts where post_type=’post'”);

while ($row = $result->fetch_object()){
$arr = (array)$row;
$diff = array_diff($arr, $arr1);
pre($diff);

}

exit;

}

Description

Array_diff() takes a values from database and compare these value, and give the different vaule.The same values or data will be eliminated.

2.array_intesect

add_action(‘init’, ‘fixing’);
function fixing(){

$mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);

$arr1 = array(“a” => “Cat”,”b” => “Dog”, “c” => “Horse”);
extract($arr1);
echo”\$a = $a; \$b = $b; \$c = $c”;
pre($arr1);

global $wpdb;
$result=$mysqli->query(“SELECT * from wp_posts where post_type=’post'”);

while ($row = $result->fetch_object()){
$arr = (array)$row;
$diff = array_intersect($arr, $arr1);
pre($diff);

}

exit;

}

Description

In this example array_intersect() compare the value and he match value.

Advertisements