'Comparison on object value with database loop
I need to compare values of an object with the email I get through a select in mysql. But the comparison is not working.
Here is code for comparison and execution if there is an equal value or not.
<?
if($data){
for($i = 0; $i < sizeof($data); $i++){
foreach($response->members as $result){
if($result->email_address === $data[$i]["usu_email"]){
$exists = "true";
}
if($exists === "true"){
echo "User Mysql: ".$data[$i]["usu_email"]." | update | Mailchimp: ".$result->email_address."</br>";
break;
}else{
echo "User Mysql: ".$data[$i]["usu_email"]." | Insert | Mailchimp: ".$result->email_address."</br>";
}
}
}
}
?>
Value in object that returns in the variable $response->members
Array ( [0] => stdClass Object ( [id] => 6a3022ed588f225aa7c48f26492932ed [email_address] => [email protected] [unique_email_id] => 1709195db4 [contact_id] => 13c74a66732323cefa6b65c0f11aaf75 [full_name] => Hebert Vianna [web_id] => 582764355 [email_type] => html [status] => subscribed [consents_to_one_to_one_messaging] => 1 [merge_fields] => stdClass Object ( [FNAME] => Hebert [LNAME] => Vianna [ADDRESS] => [PHONE] => [BIRTHDAY] => [PLANO] => mensal [INICIOPLAN] => [FIMPLANO] => ) [stats] => stdClass Object ( [avg_open_rate] => 0 [avg_click_rate] => 0 ) [ip_signup] => [timestamp_signup] => [ip_opt] => 201.92.206.63 [timestamp_opt] => 2022-02-04T20:27:13+00:00 [member_rating] => 2 [last_changed] => 2022-02-07T17:31:09+00:00 [language] => [vip] => [email_client] => [location] => stdClass Object ( [latitude] => 0 [longitude] => 0 [gmtoff] => 0 [dstoff] => 0 [country_code] => [timezone] => [region] => ) [source] => Admin Add [tags_count] => 0 [tags] => Array ( ) [list_id] => 4dd6ba9214 [_links] => Array ( [0] => stdClass Object ( [rel] => self [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed [method] => GET [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json ) [1] => stdClass Object ( [rel] => parent [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members [method] => GET [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/CollectionResponse.json [schema] => https://us14.api.mailchimp.com/schema/3.0/Paths/Lists/Members/Collection.json ) [2] => stdClass Object ( [rel] => update [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed [method] => PATCH [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json [schema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PATCH.json ) [3] => stdClass Object ( [rel] => upsert [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed [method] => PUT [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json [schema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PUT.json ) [4] => stdClass Object ( [rel] => delete [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed [method] => DELETE ) [5] => stdClass Object ( [rel] => activity [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed/activity [method] => GET [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Activity/Response.json ) [6] => stdClass Object ( [rel] => goals [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed/goals [method] => GET [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Goals/Response.json ) [7] => stdClass Object ( [rel] => notes [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed/notes [method] => GET [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Notes/CollectionResponse.json ) [8] => stdClass Object ( [rel] => events [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed/events [method] => POST [targetSchema] => https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Events/POST.json ) [9] => stdClass Object ( [rel] => delete_permanent [href] => https://us14.api.mailchimp.com/3.0/lists/4dd6ba9214/members/6a3022ed588f225aa7c48f26492932ed/actions/delete-permanent [method] => POST ) ) )
This code is checking the bank and API emails in Mailchimp, but it only informs the update action and does not display other situations.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
