There is almost identical question,但我不知道該怎麼辦我的情況。Foreach只返回一個數組元素的第一個字母?
我只是用OO PHP開始,我有我的類中此功能:
public function show() {
foreach($this->data['fields'] as $field) {
$type = $field['type'];
echo $type;
}
}
這裏的輸入數據:
當然my_function('id',
array(
'foo' => 'bar',
'bar' => 'foo',
'fields' => array(
'type' => 'my_type',
'foo' => 'bar',
'etc.' => 'value'),
),
);
中echo $field['type']
只返回的my_type
第一個字母(m
)。
我不能只是簡單地使用echo $field
因爲我有這個數組下多個鍵和返回my_typebarvalue
代替my_type
,同樣的情況與$field[0]
(mbv
)。我該怎麼辦?
我做了'echo $ field',之後所有東西都清晰了!明智的答案,非常感謝,這是如何看起來像(解釋的東西,而不是直接的答案/代碼)。謝謝! :) – Wordpressor 2012-03-27 01:57:15