php获取php数组中的值
这应该很简单,但我无法理解…我有一个php数组:php获取php数组中的值,php,wordpress,Php,Wordpress,这应该很简单,但我无法理解…我有一个php数组: Array ( [108] => WP_Post Object ( [ID] => 108 [post_author] => 1 [post_date] => 2020-07-17 19:25:21 [post_date_gmt] => 2020-07-18 00:25:21 [post_content] => [post_title] => Sight_to_See_paperback_final13-
Array ( [108] => WP_Post Object ( [ID] => 108 [post_author] => 1 [post_date] => 2020-07-17 19:25:21 [post_date_gmt] => 2020-07-18 00:25:21 [post_content] => [post_title] => Sight_to_See_paperback_final13-10-10-19 [post_excerpt] => [post_status] => inherit [comment_status] => open [ping_status] => closed [post_password] => [post_name] => sight_to_see_paperback_final13-10-10-19-2 [to_ping] => [pinged] => [post_modified] => 2020-11-29 16:09:42 [post_modified_gmt] => 2020-11-29 21:09:42 [post_content_filtered] => [post_parent] => 105 [guid] => https://legacytoo.com/wp-content/uploads/2020/07/Sight_to_See_paperback_final13-10-10-19-1.pdf [menu_order] => 0 [post_type] => attachment [post_mime_type] => application/pdf [comment_count] => 0 [filter] => raw )
如何在代码中获得“108”的值?或者,当我没有108值时,如何获取guid值。
我已从以下内容获取阵列:
$query = array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'application/pdf');
$images = get_children( $query );
我试着这样显示它:
$thisVar = $images->guid;
还有这个
$thisVar = $images[0]->guid;
两者都不起作用。这一个有效,但我没有108的值:
$thisVar = $images[108]->guid;
谢谢您的帮助。在这种情况下,您可以使用
reset($images)
获取数组中的第一个元素reset()
将指针移动到返回元素值的第一个元素,如果为空,则移动到false
更多信息:在这种情况下,您可以使用
reset($images)
获取数组中的第一个元素reset()
将指针移动到返回元素值的第一个元素,如果为空,则移动到false
更多信息:如果执行
reset($images)
,reset()
将为您提供数组中的第一个元素,您会得到什么输出。您是一个天才,非常有用,谢谢。将其作为未来参考的答案:)如果执行reset($images)
,reset()
将为您提供数组中的第一个元素。您是一个天才,非常有用,谢谢。将其作为答案供将来参考:)