-3

I have an array that has a nested array shown below, my goal is to use PHP and loop through this array pulling out both the parent and child data.

$NestedArray = array(
             "Name" => array(
                       "Phone"=>"Text",
                       "Email"=>"12"
              )
             "Company" => array(
                       "Phone"=>"Text",
                       "Email"=>"12"
              )
);

Will someone please show me how to loop through this array using php. Thank you.

2

1 Answer 1

1

Use the foreach construct

foreach($NestedArray as $sKey=>$subarray)
{
    // You can print the subarray key here too
    foreach($subarray as $key=>$value)
    {
        print $key + ": " + $value;
    }
}

if you want to print for debug purposes, use print_r

print_r($NestedArray);
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.