我在那個對象中有一個數組對象galleryImages我有像json字符串,在這個galleryImages我想要顯示第一個圖像值,如何才能獲得唯一的第一個圖像值?如何獲得數組對象的第0個索引鍵值
下面
$data=Array
(
[dbResultgallery] => Array
(
[0] => stdClass Object
(
[gallery_id] => 1
[className] => 1
[sectionName] => 1
[title] => Title 1
[description] => gfhfg
[galleryImages] => ["1.jpeg","2.jpg"]
[reg_on] => 2017-04-03 12:21:59
[created_by] => [email protected]
[school_id] => 2
[status] => 0
)
[1] => stdClass Object
(
[gallery_id] => 2
[className] => 1
[sectionName] => 1
[title] => Title 2
[description] => sdfdsfsdfsdfsdf
[galleryImages] => ["3.jpeg","4.jpg","5.jpg"]
[reg_on] => 2017-04-03 12:23:37
[created_by] => [email protected]
[school_id] => 2
[status] => 0
)
)
)
我現在用json_decode我的陣列檢查,看我下面的代碼
foreach ($dbResultgallery as $gal) :
$role = json_decode($gal->galleryImages,true);
endforeach;
現在我得到陣列格式像
Array
(
[0] => 1.jpeg
[1] => 2.jpg
)
Array
(
[0] => 3.jpeg
[1] => 4.jpg
[2] => 5.jpg
)
預期結果
我只需要在第一圖像值等1.jpeg和3.jpeg,每個陣列我只需要第0項值
更新代碼
var_dump(json_decode($ gal-> galleryImages,true ))
array(2) {
[0]=>
string(37) "6be1954c4bec91fe26fb7447fc551782.jpeg"
[1]=>
string(36) "153651d989591e76444c92cf037d5ac4.jpg"
}
array(3) {
[0]=>
string(37) "f356ceafa408e61cd1c62cfc39752b32.jpeg"
[1]=>
string(36) "a4fd29005696d92e0fc4cd3931454609.jpg"
[2]=>
string(36) "8eaaecdac1ff219192806acba7978a1b.jpg"
}
我試過,但沒有什麼是顯示 –
現在越來越像回答第一個字符串,這意味着我的圖片值one.jpeg三,JPG意味着我得到的答案像o和t –
@subikshanM好吧,你用'var_dump(json_decode($ gal-> galleryImages,true))得到了什麼? – Schlaus