2013-06-29 61 views
-2

爲什麼我會收到這些錯誤?爲什麼我會收到「非法字符串偏移」錯誤?

警告:非法串成 'en' 偏移C:\ XAMPP \ htdocs中\包括在線路\ stream.class.php 48

警告:非法字符串 'EN' 在C的失調:\ XAMPP \ htdocs \ includes \ stream.class.php on line 60

這是我的代碼。

$s['target_data']['title'] = $s['target_data']['title']['en']; 
$s['target_data']['description'] = $s['target_data']['description']['en']; 

回答

3

問題是,$s['target_data']['title']是一個字符串,而不是你所期待的數組。

PHP允許您使用數組類型語法索引到一個字符串($string[0]返回$string第一個字符,例如),但只有數字指標就像[0] - 你不能用string指標像["en"],這錯誤是在抱怨什麼。

您顯示的代碼似乎試圖將一個變量從一個數組轉換爲一個字符串並將其存儲回相同的變量。你可能會運行它兩次 - 然後第二次得到錯誤,因爲它不再是一個數組?

+0

爲什麼downvote?這個答案有什麼問題嗎? – jcsanyi

-1
(array) $s['target_data']['title'] = (array) $s['target_data']['title']['en']; 


    (array) $s['target_data']['description'] = (array)$s['target_data']['description']['en']; 

如果你的$ S [ 'target_data'] [ '說明']和$ S [ 'target_data'] [ '標題']不是數組,你可以將它轉換爲(陣列)

+0

這可能會修復錯誤,但它總是返回null(並可能會爲未定義的數組索引生成警告) - 在實際查找「en」元素時不是很有用。 – jcsanyi

+0

你是對的,通知將被顯示。如果[en]索引爲空,則結果始終爲空。然後必須在[en]索引上工作 –

相關問題