Reputation: 873
I have the following code sample
private $analyze_types = array(
"1" => array(
'level' => '4',
'l1' => '-1',
'l2' => '-1',
'l3' => '-1',
'l4' => '-1',
'l5' => '-1'
),
"226" => array(
'level' => '-1',
'l1' => '-1',
'l2' => '-1',
'l3' => '2',
'l4' => '3',
'l5' => '4'
)
);
How can i get value of "1" and if I want to get 'level' value, what should i do?
Upvotes: 1
Views: 31190
Reputation: 88
You can try array_column (http://php.net/manual/en/function.array-column.php)
eg.:
$levels = array_column($this->analyze_types, 'level');
Upvotes: 2
Reputation: 5463
You can get the keys of an array by doing the following, if that's what you're asking?
$keys = array_keys($this->analyze_types);
print_r($keys);
Now that you have an array of keys you can simply loop through them to execute more code, for example:
foreach($keys as $k) {
echo $k; //This will echo out 1
}
Upvotes: 1
Reputation: 904
PHP :
foreach( $this->analyze_types as $key => $value) {
echo $key; // output 1 and 226
echo $value['level']; // output 4 and -1
}
Upvotes: 5
Reputation: 11061
To get element with index 'level'
of subarray with index '1'
in main array you should use just
$this->analyze_types[1]['level']
Upvotes: 3