简体   繁体   中英

get values from an array on php

hello I have a code to save values ​​in a user meta (I use 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.

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. 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

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); 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?

I would recommend doing a foreach loop over your $emails_all_subscription results. Trying doing your echo print_r statement in there.

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.

Not sure if you need them but they are available here ->

https://www.php.net/manual/en/function.array-values.php

try var_dump($_POST); to make sure if there are data sent in post method, if it was empty, try to check var_dump($_GET) ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM