你好可爱的人类...
我正在使用 WordPress 的高级自定义字段插件,并且试图弄清楚如何从数组中的数组中访问某些值。
这是我的数组:
array(4) {
[0]=;
array(1) {
["image"]=>;
array(10) {
["id"]=>
int(282)
["alt"]=>
string(12) "Cable bundle"
["title"]=>
string(12) "Cable bundle"
["caption"]=>
string(0) ""
["description"]=>
string(0) ""
["mime_type"]=>
string(9) "image/png"
["url"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o.png"
["width"]=>
int(1280)
["height"]=>
int(960)
["sizes"]=>
array(33) {
["thumbnail"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-220x150.png"
["thumbnail-width"]=>
int(220)
["thumbnail-height"]=>
int(150)
["medium"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-300x225.png"
["medium-width"]=>
int(300)
["medium-height"]=>
int(225)
["large"]=>
string(92) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-1024x768.png"
["large-width"]=>
int(640)
["large-height"]=>
int(480)
["cat_post_thumb_sizecategoryposts-2"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o.png"
["cat_post_thumb_sizecategoryposts-2-width"]=>
int(1280)
["cat_post_thumb_sizecategoryposts-2-height"]=>
int(960)
["cat_post_thumb_sizecategoryposts-3"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-220x150.png"
["cat_post_thumb_sizecategoryposts-3-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-3-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-4"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o.png"
["cat_post_thumb_sizecategoryposts-4-width"]=>
int(1280)
["cat_post_thumb_sizecategoryposts-4-height"]=>
int(960)
["cat_post_thumb_sizecategoryposts-5"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-150x150.png"
["cat_post_thumb_sizecategoryposts-5-width"]=>
int(150)
["cat_post_thumb_sizecategoryposts-5-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-6"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-220x150.png"
["cat_post_thumb_sizecategoryposts-6-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-6-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-7"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-220x150.png"
["cat_post_thumb_sizecategoryposts-7-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-7-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-8"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-220x150.png"
["cat_post_thumb_sizecategoryposts-8-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-8-height"]=>
int(150)
["home-page"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6773761367_bc13aec4a5_o-530x250.png"
["home-page-width"]=>
int(530)
["home-page-height"]=>
int(250)
}
}
}
[1]=>
array(1) {
["image"]=>
array(10) {
["id"]=>
int(281)
["alt"]=>
string(7) "Circuit"
["title"]=>
string(7) "Circuit"
["caption"]=>
string(0) ""
["description"]=>
string(0) ""
["mime_type"]=>
string(10) "image/jpeg"
["url"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b.jpg"
["width"]=>
int(1024)
["height"]=>
int(768)
["sizes"]=>
array(33) {
["thumbnail"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-220x150.jpg"
["thumbnail-width"]=>
int(220)
["thumbnail-height"]=>
int(150)
["medium"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-300x225.jpg"
["medium-width"]=>
int(300)
["medium-height"]=>
int(225)
["large"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b.jpg"
["large-width"]=>
int(640)
["large-height"]=>
int(480)
["cat_post_thumb_sizecategoryposts-2"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b.jpg"
["cat_post_thumb_sizecategoryposts-2-width"]=>
int(1024)
["cat_post_thumb_sizecategoryposts-2-height"]=>
int(768)
["cat_post_thumb_sizecategoryposts-3"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-220x150.jpg"
["cat_post_thumb_sizecategoryposts-3-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-3-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-4"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b.jpg"
["cat_post_thumb_sizecategoryposts-4-width"]=>
int(1024)
["cat_post_thumb_sizecategoryposts-4-height"]=>
int(768)
["cat_post_thumb_sizecategoryposts-5"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-150x150.jpg"
["cat_post_thumb_sizecategoryposts-5-width"]=>
int(150)
["cat_post_thumb_sizecategoryposts-5-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-6"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-220x150.jpg"
["cat_post_thumb_sizecategoryposts-6-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-6-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-7"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-220x150.jpg"
["cat_post_thumb_sizecategoryposts-7-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-7-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-8"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-220x150.jpg"
["cat_post_thumb_sizecategoryposts-8-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-8-height"]=>
int(150)
["home-page"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/6500613825_911abf3799_b-530x250.jpg"
["home-page-width"]=>
int(530)
["home-page-height"]=>
int(250)
}
}
}
[2]=>
array(1) {
["image"]=>
array(10) {
["id"]=>
int(280)
["alt"]=>
string(9) "TV cables"
["title"]=>
string(9) "TV cables"
["caption"]=>
string(0) ""
["description"]=>
string(0) ""
["mime_type"]=>
string(10) "image/jpeg"
["url"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o.jpg"
["width"]=>
int(1280)
["height"]=>
int(800)
["sizes"]=>
array(33) {
["thumbnail"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-220x150.jpg"
["thumbnail-width"]=>
int(220)
["thumbnail-height"]=>
int(150)
["medium"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-300x187.jpg"
["medium-width"]=>
int(300)
["medium-height"]=>
int(187)
["large"]=>
string(92) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-1024x640.jpg"
["large-width"]=>
int(640)
["large-height"]=>
int(400)
["cat_post_thumb_sizecategoryposts-2"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o.jpg"
["cat_post_thumb_sizecategoryposts-2-width"]=>
int(1280)
["cat_post_thumb_sizecategoryposts-2-height"]=>
int(800)
["cat_post_thumb_sizecategoryposts-3"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-3-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-3-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-4"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o.jpg"
["cat_post_thumb_sizecategoryposts-4-width"]=>
int(1280)
["cat_post_thumb_sizecategoryposts-4-height"]=>
int(800)
["cat_post_thumb_sizecategoryposts-5"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-150x150.jpg"
["cat_post_thumb_sizecategoryposts-5-width"]=>
int(150)
["cat_post_thumb_sizecategoryposts-5-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-6"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-6-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-6-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-7"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-7-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-7-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-8"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-8-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-8-height"]=>
int(150)
["home-page"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/5249206215_be7e8572d8_o-530x250.jpg"
["home-page-width"]=>
int(530)
["home-page-height"]=>
int(250)
}
}
}
[3]=>
array(1) {
["image"]=>
array(10) {
["id"]=>
int(279)
["alt"]=>
string(0) ""
["title"]=>
string(11) "CAT5 Cables"
["caption"]=>
string(0) ""
["description"]=>
string(11) "CAT5 Cables"
["mime_type"]=>
string(10) "image/jpeg"
["url"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o.jpg"
["width"]=>
int(1536)
["height"]=>
int(2048)
["sizes"]=>
array(33) {
["thumbnail"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-220x150.jpg"
["thumbnail-width"]=>
int(220)
["thumbnail-height"]=>
int(150)
["medium"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-225x300.jpg"
["medium-width"]=>
int(225)
["medium-height"]=>
int(300)
["large"]=>
string(92) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-768x1024.jpg"
["large-width"]=>
int(640)
["large-height"]=>
int(853)
["cat_post_thumb_sizecategoryposts-2"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o.jpg"
["cat_post_thumb_sizecategoryposts-2-width"]=>
int(1536)
["cat_post_thumb_sizecategoryposts-2-height"]=>
int(2048)
["cat_post_thumb_sizecategoryposts-3"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-3-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-3-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-4"]=>
string(83) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o.jpg"
["cat_post_thumb_sizecategoryposts-4-width"]=>
int(1536)
["cat_post_thumb_sizecategoryposts-4-height"]=>
int(2048)
["cat_post_thumb_sizecategoryposts-5"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-150x150.jpg"
["cat_post_thumb_sizecategoryposts-5-width"]=>
int(150)
["cat_post_thumb_sizecategoryposts-5-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-6"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-6-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-6-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-7"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-7-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-7-height"]=>
int(150)
["cat_post_thumb_sizecategoryposts-8"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-220x150.jpg"
["cat_post_thumb_sizecategoryposts-8-width"]=>
int(220)
["cat_post_thumb_sizecategoryposts-8-height"]=>
int(150)
["home-page"]=>
string(91) "http://www.XXXXXXXX.com/dev/wp-content/uploads/2013/11/1543218761_62cea76758_o-530x250.jpg"
["home-page-width"]=>
int(530)
["home-page-height"]=>
int(250)
}
}
}
}
我需要为["home-page"]
数组中的四个图像中的每一个获取存储的 URL,因为它用于正确大小的图像,显然它需要遍历整个数组。基本上,我需要了解如何访问该级别的数组。我已经阅读了一些内容,但我仍然不明白。我需要多个foreach
循环吗?
到目前为止,我有这个:
$images = get_field('homepage_image');
foreach ($images as $key => $image ) {
foreach ($image as $subkey => $value) {
foreach ($value as $subsubkey => $subvalue) {
foreach ($subvalue as $subsubsubkey => $subsubvalue) {
$imageURL = $subsubvalue ['home-page'];
echo $imageURL;
echo "<br />"; }
}
}
}
这似乎输出了字母 ha 几次。谁能告诉我我做错了什么?可能有更好的方法,但我想了解这一点。
干杯托比