我是 php
新手。我只想从字符串数组创建一个对象。
我想要这些字符串数组:
$arrEmails = [
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4a202522242e252f0a2f272b232664292527" rel="noreferrer noopener nofollow">[email protected]</a>',
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="14727b7b767566547179757d783a777b79" rel="noreferrer noopener nofollow">[email protected]</a>',
'<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4849180918687999d809cb49199959d98da979b99" rel="noreferrer noopener nofollow">[email protected]</a>'
];
放入要访问的对象中,例如,
$emails = $objEmails->电子邮件
这怎么可能?
最佳答案
只需创建空对象并添加该属性即可:
$objEmails = new stdClass; // initialize an empty object
$objEmails->email = $arrEmails; // declare the property
关于php - 如何在 PHP 中从字符串数组创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29576641/