[英]get values from an array on php
hello I have a code to save values in a user meta (I use wordpress).你好我有一个代码可以在用户元中保存值(我使用 wordpress)。 in my case I save emails from a subscription form and my idea is to get the emails and use them to create a variable that includes wp_mail to send an email to each one, for example a successful subscription email and others.
在我的情况下,我从订阅表格中保存电子邮件,我的想法是获取电子邮件并使用它们来创建一个包含 wp_mail 的变量,以向每个人发送电子邮件,例如成功的订阅电子邮件和其他电子邮件。
To save the values I found: Add values to User Meta Field within an array要保存我找到的值: 将值添加到数组中的用户元字段
Since until now I did not know how to save and obtain many values without losing the ones I already had in the wordpress user_meta.因为直到现在我都不知道如何在不丢失 wordpress user_meta 中已有的值的情况下保存和获取许多值。 That seems to have worked for me by the way, if not, I appreciate if you tell me , if you understand what I need to do.
顺便说一下,这似乎对我有用,如果没有,我很感激你告诉我,如果你明白我需要做什么。
so I save them:所以我保存了它们:
if (isset ($_POST ['sub_sus'])) {
$email_subscribers2 = $_POST['email_sus'];
$subscriber_list2 = get_user_meta ($vendor_id, 'subscribers3', false);
if (! array($subscriber_list2)) {
$subscriber_list2 = array ();
}
$subscriber_list2[] = $email_subscribers2;
update_user_meta($vendor_id, 'subscribers3', $ subscriber_list2);
}
but I don't know how to get them, I know they are saved because I see them here:但我不知道如何得到它们,我知道它们得救了,因为我在这里看到它们:
$emails_all_subscription = get_user_meta ($vendor_id, 'subscribers3', false);
echo print_r($emails_all_subscription);
the result:结果:
Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => Array (
[0] => luu@gmail.com
)
[1] => my@gmail.com
)
[1] => 333@gmail.com
)
[1] => 22@gmail.com
)
[1] => 44@gmail.com
)
[1] => tiendanandito@gmail.com
)
[1] => dfghdfg@gmail.com
)
[1] => dsfdsf34@gmail.com
)
[1] => 888@gmail.com
)
[1] => 4opp@hotmail.com
)
[1] => 99999999@hotmaoil.com
)
)
1
But what I need is to get only the emails as a result and not the rest of the Array ([0] =>. I only want the emails and separated by commas for example, in order to send them in a variable to wp_mail但我需要的是只获取电子邮件作为结果,而不是数组的其余部分([0] =>。例如,我只想要电子邮件并用逗号分隔,以便将它们作为变量发送到 wp_mail
some help?一些帮助? Thanks in advance
提前致谢
Use the translator that is why it does not see exactly as it should but I think it is perfectly understood.使用翻译器,这就是为什么它没有完全按照它应该看到的,但我认为它是完全理解的。 sorry
对不起
I already tried echo var_dump ($ emails_all_subscription);我已经试过 echo var_dump ($ emails_all_subscription); but instead of returning only the emails it gives me even much more array text
但它不是只返回电子邮件,而是给了我更多的数组文本
array(1) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(2) {
[0]=> array(1) {
[0]=> string(13) "luu@gmail.com"
}
[1]=> string(13) "mio@gmail.com"
}
[1]=> string(13) "333@gmail.com"
}
[1]=> string(12) "22@gmail.com" } [1]=> string(12) "44@gmail.com" } [1]=> string(23) "tiendanandito@gmail.com" } [1]=> string(17) "dfghdfg@gmail.com" } [1]=> string(18) "dsfdsf34@gmail.com" } [1]=> string(13) "888@gmail.com" } [1]=> string(16) "4opp@hotmail.com" } [1]=> string(21) "99999999@hotmaoil.com" } }
I don't know if I'm wrong, but I think that each value is saved in an array within the previous array and so on, because when I open a foreach it returns array and I open a foreach within the previous foreach it returns array and the last email, if I open another foreach more within the previous ones then return the before the last email and an array and so on, then, it is wrong how I am saving or creating the array, right?我不知道我是否错了,但我认为每个值都保存在前一个数组中的一个数组中,依此类推,因为当我打开一个 foreach 时它返回数组,而我在前一个 foreach 中打开一个 foreach 它返回数组和最后一封电子邮件,如果我在前一封邮件中再打开另一个 foreach 然后返回最后一封电子邮件之前的邮件和一个数组等等,那么,我保存或创建数组的方式是错误的,对吗?
I would recommend doing a foreach loop over your $emails_all_subscription results.我建议对您的 $emails_all_subscription 结果进行 foreach 循环。 Trying doing your echo print_r statement in there.
试着在那里做你的 echo print_r 语句。
Depending on how that looks you can then further access just the value with [] brackets, there are also some array_functions you can look at as well.根据它的外观,您可以进一步访问带有 [] 括号的值,还有一些 array_functions 您也可以查看。
Not sure if you need them but they are available here ->不确定您是否需要它们,但它们在此处可用 ->
https://www.php.net/manual/en/function.array-values.php https://www.php.net/manual/en/function.array-values.php
try var_dump($_POST);
尝试
var_dump($_POST);
to make sure if there are data sent in post method, if it was empty, try to check var_dump($_GET)
;确定post方法中是否有数据发送,如果为空,尝试检查
var_dump($_GET)
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.