php - json循环php,带有不带id的数组

标签 php arrays

我有这个 json 数组,没有 id 和可变电子邮件号码:

数组包含多个电子邮件,以逗号分隔:

[{"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c59445d514c50597c48594f48125f5351" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"processed","category":"cat facts","sg_event_id":"FDl9L7nP4zJXgLYUGhqqoA==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89d80999588949db88c9d8b8cd69b9795" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"deferred","category":"cat facts","sg_event_id":"jbtTInm9Pej80gzRXRg9Pg==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","response":"400 try again later","attempt":"5"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="503528313d203c3510243523247e333f3d" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"delivered","category":"cat facts","sg_event_id":"XUBvHRS8T0eD_Eea8IECDA==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","response":"250 OK"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="22475a434f524e4762564751560c414d4f" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"open","category":"cat facts","sg_event_id":"Wp2888u5ZaJX7Pd-_DbFpA==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","useragent":"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","ip":"255.255.255.255"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8aeff2ebe7fae6efcafeeff9fea4e9e5e7" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"click","category":"cat facts","sg_event_id":"7iXIm9S5SAuhRmoy4QIZZg==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","useragent":"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","ip":"255.255.255.255","url":"http://www.sendgrid.com/"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75100d141805191035011006015b161a18" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"bounce","category":"cat facts","sg_event_id":"3HJSeIIA2FzBjQxXvlf2hQ==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","reason":"500 unknown recipient","status":"5.0.0"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9affe2fbf7eaf6ffdaeeffe9eeb4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"dropped","category":"cat facts","sg_event_id":"8acL8P-wxlb0CJoxBEjYuQ==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","reason":"Bounced Address","status":"5.0.0"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d48554c405d41486d59485e59034e4240" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"spamreport","category":"cat facts","sg_event_id":"cgn6ggkYz1S7XT5D5nRo9w==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e6839e878b968a83a692839592c885898b" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"unsubscribe","category":"cat facts","sg_event_id":"suFV8ITF-9ND3j1SrlW-fA==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0"},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f99c81989489959cb98d9c8a8dd79a9694" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"group_unsubscribe","category":"cat facts","sg_event_id":"KljxrqIWTvF0mEshFKnw1Q==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","useragent":"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","ip":"255.255.255.255","url":"http://www.sendgrid.com/","asm_group_id":10},
 {"email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74110c151904181134001107005a171b19" rel="noreferrer noopener nofollow">[email protected]</a>","timestamp":1516820089,"smtp-id":"\u003c14c5d75ce93.dfd.64b469@ismtpd-555\u003e","event":"group_resubscribe","category":"cat facts","sg_event_id":"F7oTvsqxOIQyRWyLJeXIjA==","sg_message_id":"14c5d75ce93.dfd.64b469.filter0001.16648.5515E0B88.0","useragent":"Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","ip":"255.255.255.255","url":"http://www.sendgrid.com/","asm_group_id":10}]

我需要创建一个 while/loop 来获取单独的电子邮件数据,我也尝试过

$obj = json_decode( file_get_contents( 'php://input' ) );
foreach ($obj as $value) {    
   $value->email;
}

但它始终仅返回第一个或最后一个值

最佳答案

如果您知道数组键,这应该对您有用,并且它消除了双循环。

$array = json_decode(file_get_contents( 'php://input' ), true);
foreach($array as $innerArray){
    $emails[] = $innerArray['email'];
    //or do whatever you want with each email as $innerArray['email'], repeat for each key.
}

关于php - json循环php,带有不带id的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48430103/

相关文章:

javascript - 利用 document.forms[0].elements ['someid' ].style.backgroundColor

php - 显示预订系统 php 中哪些区域可用

arrays - 循环声音 ActionScript Flash

c++ - 在 C++ 中创建一个全局对象数组

c - 将数组传递给 scanf 函数和变量

c++ - 将列表分成相等的部分?

php - 如何在mysql中管理并发?

php - 如何准备方法/函数调用以便稍后调用它?

javascript - 如何获取mysql中前两行值并将其与 session 用户变量的值进行比较?

php - 如何在 PHP 中根据另一个(部分)数组的值对数组进行排序?