Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1062603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:39:10+00:00 2026-05-16T18:39:10+00:00

I have to test an array with inner arrays. my array looks like the

  • 0

I have to test an array with inner arrays.

my array looks like the following.

$testdata=Array
    (
        [0] => Array
            (
                [label] => 'Ammy'
                [idr] => 'user7'
                [rel] => 7
            )

        [1] => Array
            (
                [label] => 'sidh'
                [idr] => user8
                [rel] => 8
            )

        [2] => Array
            (
                [label] => 'Alan'
                [idr] => 'user9'
                [rel] => 9
            )
    )

in this case my requirement is to assert whether the keys for inner array present using assertArrayHasKey() assertion of phpunit. I tried to do it like this

foreach ($testdata as $values) {
 //print_r($values);
  $this->assertArrayHasKey('idr', $values);
  $this->assertArrayHasKey('rel', $values);

}

but this is not working for me. even the control does not go inside the foreach() loop.

please suggest me some solution for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:39:10+00:00Added an answer on May 16, 2026 at 6:39 pm
    foreach ($testdata as $values) {
     //print_r($values);
      $this->assertArrayHasKey('idr', $values);
      $this->assertArrayHasKey('rel', $values);
    
    }
    

    this part in my question works fine. actually i was not getting the array itself in the test scenario. so it was not going inside the foreach(). now it is solved. i had a mistake in passing args to the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array with an array in it. It looks like: @test =(
i have an array in php like this: $arr['test'] = asd; $arr['test1'] = asd1;
I have the following array of structures called test, where each field is a
I have two arrays: $array1 = array(1=>1,10=>1,12=>0,13=>13); $array2 = array(1=>Hello,10=>Test,12=>check,13=>error); Here $array1 has keys
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have an array of arrays. The inner array is 16 slots, each with
I have a file test.txt which has an array: array = [3,5,6,7,9,6,4,3,2,1,3,4,5,6,7,8,5,3,3,44,5,6,6,7] Now what
Let's say I have an array var test = new Array() the values in
I have this array $test = $_POST['test']; print_r($test); Array ( [0] => Array (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.