0

I have an array, which is consist of many arrays. So i want to execute foreach loop on it. I want to generate options from it.

Array

Array
(
    [0] => Array
        (
            [user_id] => 201
            [first_name] => ayaz
        )
    [1] => Array
        (
            [user_id] => 212
            [first_name] => khalique
        )
)

I have tried

 <?php foreach($UserDataEmail as $user){
            foreach($user as $val){?>
                <option value="<?=$val['user_id']?>" ><?=$val['first_name']?></option>
            <?php }
    }// end foreach ?>

But it does not work, can any one guide me where i'm wrong. Thanks

1 Answer 1

2

You do not need the next foreach loop as you can access the values directly from there -

 <?php foreach($UserDataEmail as $user){ ?>
     <option value="<?=$user['user_id']?>" ><?=$user['first_name']?></option>
 <?php }// end foreach ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.