Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Quick PHP warning fix

$
0
0

Replies: 0


if ( is_array( $photos ) ) {
	$first_photo = array_pop( array_reverse( $photos ) );
}

causes a PHP Strict warning about passing by reference. I believe this is equivalent and supported in all PHP releases:


if ( is_array( $photos ) && count( $photos ) > 0 ) {
	$first_photo = array_values( $photos )[0];
}
  • This topic was modified 10 minutes ago by . Reason: code formatting

Viewing all articles
Browse latest Browse all 59525

Trending Articles