關聯數組$ myArray的的的var_dump如下:值關聯數組元素的不被識別爲字符串
array (size=522)
0 =>
array (size=3)
'id' => int 1
'url' => string 'introduction' (length=12)
'title' => string 'Introduction' (length=12)
1 =>
array (size=3)
'id' => int 2
'url' => string 'first_steps' (length=11)
'title' => string 'First steps' (length=11)
2 => ...
當我分配關聯數組中元素的值到一個功能,以執行一些字符串操縱,我得到一個錯誤:
"Catchable fatal error: Argument 1 passed to doStringManipulation() must be an instance of string, string given, ..."
的字符串操作被稱爲foreach循環中:
foreach($myArray as $row){
...
$s = doStringManipulation((string) $row['url']); // triggers error
...
}
function doStringManipulation(string str){
...
return $result; // string
}
無論我是否將$ row ['url']轉換爲字符串都沒有區別。儘管var_dump確認元素值是一個字符串,但我總是得到錯誤。
我在這裏錯過了什麼?
謝謝!
的PHP版本您使用的? – Robert
您是否嘗試過不將$ row ['url']作爲參數,但例如「test」? (嘗試沒有投) –
也許這可以幫助http://stackoverflow.com/questions/4103480/really-php-argument-1-passed-to-my-function-must-be-an-instance-of-string -s –