Reputation: 71
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?
Upvotes: 1
Views: 194
Reputation: 32810
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.
Upvotes: 0
Reputation: 404
Loop through the array and get the 'installed' key's value:
foreach ($array as $innerArray) {
echo $innerArray['installed'];
}
Upvotes: 0
Reputation: 361
foreach ($array as $value)
{
echo $value['installed']. "<br />";
}
will output
1 1
Upvotes: 1
Reputation: 255095
Absolutely the same way like when you iterate 1 dimensional array:
foreach ($array as $value) {
var_dump($value);
var_dump($value['installed'];
}
Upvotes: 0