我的数组如下所示如何显示消息的值和任何键。
(
[@@warning_count] => 2
[0] => Array
(
[Level] => Warning
[Code] => 1366
[Message] => Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1
)
[1] => Array
(
[Level] => Error
[Code] => 1062
[Message] => Duplicate entry ‘peace′ for key ‘groupname’
)
)
答案 0 :(得分:1)
尝试以下代码......
<?php
$my_array = array ('@@warning_count' => 2,
0 => Array (
'Level' => 'Warning',
'Code' => '1366',
'Message' => 'Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1',
),
1 => Array(
'Level' => 'Error',
'Code' => '1062',
'Message' => 'Duplicate entry ‘peace′ for key ‘groupname’',
),
);
foreach ($my_array as $arr_key => $arr_val){
if(is_array($arr_val) == true ){
echo $arr_val['Message'];
}
}
?>
让我知道上面的代码...
答案 1 :(得分:0)
foreach($arr as $val) {
echo $val['Level'] . "\n";
echo $val['Code'] . "\n";
echo $val['Message'] . "\n";
}
或
foreach($arr as $val) {
for($val as $innerKey => $innerValue) {
echo $innerKey . ' == ' . $innerValue . "\n";
}
}
答案 2 :(得分:0)
这是您想要达到的结果吗?
<?php
$dataArray = Array(
array(
'Level' => 'Warning',
'Code' => '1366',
'Message' => 'Message here 1',
),
array(
'Level' => 'Warning',
'Code' => '1062',
'Message' => 'Message here 2',
),
array(
'Level' => 'Warning',
'Code' => '3233',
'Message' => 'Message here 3',
)
);
// This shows the whole array:
echo '<pre>';
var_dump($dataArray);
echo '</pre>';
// Select only the messages:
foreach ($dataArray as $key => $value) {
echo $value['Message'].'<br />';
}
?>
答案 3 :(得分:0)
我想你想要这样的东西。参考the working code:
<?php
$myArray = array(
'@@warning_count' => 2,
array(
'level' => 'Warning',
'code' => 1266,
'message' => "Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1"),
array(
'level' => 'Warning',
'code' => 1266,
'message' => "Incorrect integer value: ‘Johny’ for column ‘billing_cycle’ at row 1"),
);
print "Warning Count: {$myArray['@@warning_count']}\n";
print "------------------\n\n";
foreach ($myArray as $key => $value){
if (is_array($value)){
foreach ($value as $subKey => $subValue){
print $subKey . "=>" . $subValue . "\n";
}
print "------------------\n";
}
}