0

this is a part of the array :

Array
(
    [0] => Array
        (
            [account_id] => 104318839768212
            [id] => act_104318839768212
            [adcampaigns] => Array
                (
                    [data] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 6011516331779
                                )

                            [1] => Array
                                (
                                    [id] => 6011399418379
                                )

                            [2] => Array
                                (
                                    [id] => 6008328196979
                                )

                        )

                    [paging] => Array
                        (
                            [cursors] => Array
                                (
                                    [after] => NjAwODMyODE5Njk3OQ==
                                    [before] => NjAxMTUxNjMzMTc3OQ==
                                )

                        )

                    [count] => 3
                    [limit] => 100
                    [offset] => 0
                )

        )

I am trying to access the ids under adcampaign and list them with a foreach loop I tried this :

 <?php foreach($ad_accounts as $ad_act): ?>
   <li><a href="#"><input type="radio" name="ad_act" value="<?php echo $ad_act['adcampaigns']['data']['id']; ?>" ><?php echo $ad_act['adcampaigns']['data']['id']; ?></a></li>
                      <?php endforeach; ?>

it returns white.any help please

1
  • 1
    try a iterator in loop like $ad_act['adcampaigns']['data'][$i]['id'] Commented Nov 19, 2013 at 10:13

3 Answers 3

2

Please try this you get ID value of data

<?
$ad_accounts = Array("0" => Array
        (
            "account_id" => 104318839768212,
            "id" => act_104318839768212,
            "adcampaigns" => Array
                (
                    "data" => Array
                        (
                            "0" => Array
                                (
                                    "id" => 6011516331779
                                ),

                            "1" => Array
                                (
                                    "id" => 6011399418379
                                ),

                            "2" => Array
                                (
                                    "id" => 6008328196979
                                )

                        ),

                    "paging" => Array
                        (
                            "cursors" => Array
                                (
                                    "after" => "NjAwODMyODE5Njk3OQ==",
                                    "before" => "NjAxMTUxNjMzMTc3OQ=="
                                )

                        )


                )

        )
);

foreach($ad_accounts[0]['adcampaigns']['data'] as $ad_act => $ad_value ){
   echo $ad_value['id'];
} ?>
Sign up to request clarification or add additional context in comments.

Comments

1

You need another loop :

<?php foreach($ad_accounts as $ad_act):

    for ($i=0; $i < count($ad_act['adcampaigns']['data']); $i++) {  ?>
        <li><a href="#">
        <input type="radio" name="ad_act" value="<?php echo $ad_act['adcampaigns']['data'][$i]['id']; ?>" >
        <?php echo $ad_act['adcampaigns']['data'][$i]['id']; ?>
        </a></li>
    <?php }  ?>
<?php endforeach; ?>

1 Comment

your code has mistakes. you closed the php tag and then using for ?
-1

You are using : after the foreach

<?php foreach($ad_accounts as $ad_act): ?> 

correct this and try

1 Comment

You should probably check the alternative syntax for PHP.

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.