1

I have the following array. how can I get the value of 'installed' key i.e 1. which value I have to check in my application.

Array
(
    [0] => Array
        (
            [id] => 53686899
        )

    [1] => Array
        (
        [installed] => 1
            [id] => 542813519
        )

    [2] => Array
        (
        [installed] => 1
            [id] => 567790764
        )
     [3] => Array
        (

            [id] => 567570764
        )
)

using foreach loop how can i do this job? anybody can plz help me?

4 Answers 4

1
foreach ($array as $value)
{
   echo $value['installed']. "<br />";
}

will output

1 1

Sign up to request clarification or add additional context in comments.

Comments

0

Try this :

foreach ($array as $value){
   if(array_key_exists('installed',$value)){
      echo $value['installed']. "<br />";
   }
}

If you are not checking for array_key_exists it will show error in first loop.

2 Comments

If you are not checking for array_key_exists it will show error in first loop.
Thanks a lot Mr. Prasanth.
0

Absolutely the same way like when you iterate 1 dimensional array:

foreach ($array as $value) {
    var_dump($value);
    var_dump($value['installed'];
}

4 Comments

@Debendra Samal: do you have something more objective than your thoughts? And how is it different from the checked answer?
actually I want to checked in this array whether the array contain installed key or not? If installed key is there, I ll do some operation and if not then also I have some operation.
@Debendra Samal: "actually I want to checked in this array whether the array contain installed key or not?" --- we cannot read your mind. If you wanted that - you had to impress that by words in the original question
Btw I got my ans.Thanks to all for kind support.
0

Loop through the array and get the 'installed' key's value:

foreach ($array as $innerArray) {
    echo $innerArray['installed'];
}

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.