how to access arry of objects in php

Advertisements

I have this result from var_dump($_REQUEST);

array(1) { ["email"]=> array(2) { [0]=> string(15) "email1@example.com" [1]=> string(15) "email2@example.com" } }

How to iterate through the arry so that I can get like this result:

$email[0]=email1@example.com
$email[1]=email2@example.com

Update: Edited the indexes

Update2:

I used:

$email = $_REQUEST['email'];
var_dump($email);

but now I am getting:

array(2) { [0]=> string(18) "email1@example.com" [1]=> string(18) "email2@example.com" }

>Solution :

$_REQUEST['email'] is the array you want to iterate through.

foreach ($_REQUEST['email'] as $i => $email) {
    $num = $i + 1;
    echo "\$email[$num]=$email<br>";
}

Leave a ReplyCancel reply