我有一個CMS我正在使用的序列化數據庫中的數據。我使用unserialize()函數將數據轉換爲關聯數組。現在我有一個很難從關聯數組拉動形象價值:我怎樣才能得到在這個關聯數組中的鍵值
這是一個簡單的while循環,我通過行使用循環:
while($row = mysql_fetch_assoc($query_models)){
$model_name = $row['ModelName'];
$model_thumbnail = unserialize($row['info']);
}
這是鍵和值陣列的我需要得到的值,所以可正確縮略圖圖像分配給尊重人:
[「1x_filename」] =>串(19)「00/83/83-設置-1X。 jpg「
整個陣列在下面,我的目標鎖定位置在更多om此陣列:
array(1) {
["thumbs"]=> array(2) {
[16]=> array(17) {
["id"]=> string(2) "82"
["1x_width"]=> string(3) "220"
["1x_height"]=> string(3) "330"
["2x_width"]=> string(3) "440"
["2x_height"]=> string(3) "660"
["3x_width"]=> string(3) "660"
["3x_height"]=> string(3) "990"
["4x_width"]=> string(3) "880"
["4x_height"]=> string(4) "1320"
["width"]=> string(3) "220"
["height"]=> string(3) "330"
["retinamode"]=> string(1) "1"
["filename"]=> string(10) "82-set.jpg"
["1x_filename"]=> string(19) "00/82/82-set-1x.jpg"
["2x_filename"]=> string(19) "00/82/82-set-2x.jpg"
["3x_filename"]=> string(19) "00/82/82-set-3x.jpg"
["4x_filename"]=> string(19) "00/82/82-set-4x.jpg"
}
[17]=> array(17) {
["id"]=> string(2) "83"
["1x_width"]=> string(3) "106"
["1x_height"]=> string(3) "150"
["2x_width"]=> string(3) "212"
["2x_height"]=> string(3) "300"
["3x_width"]=> string(3) "318"
["3x_height"]=> string(3) "450"
["4x_width"]=> string(3) "424"
["4x_height"]=> string(3) "600"
["width"]=> string(3) "106"
["height"]=> string(3) "150"
["retinamode"]=> string(1) "1"
["filename"]=> string(10) "83-set.jpg"
["1x_filename"]=> string(19) "00/83/83-set-1x.jpg"
["2x_filename"]=> string(19) "00/83/83-set-2x.jpg"
["3x_filename"]=> string(19) "00/83/83-set-3x.jpg"
["4x_filename"]=> string(19) "00/83/83-set-4x.jpg"
}
}
}
任何幫助將不勝感激。謝謝!
其添加爲像這樣的代碼很難看到任何東西 –
按鈕可以通過用四個空格縮進來自動格式化這樣的東西。 – tadman
**警告**:如果您只是在學習PHP,請不要學習過時的['mysql_query'](http://php.net/manual/en/function.mysql-query.php)界面。這很糟糕,並且已經在PHP 7中被刪除了。像[PDO不是很難學的東西](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-php-pdo- for-database-access /)以及[PHP The Right Way](http://www.phptherightway.com/)等指南有助於解釋最佳實踐。確保**你的用戶參數[妥善轉義](http://bobby-tables.com/php),否則你將以嚴重的[SQL注入漏洞](http://bobby-tables.com/ )。 – tadman