3v4l.org

run code in 300+ PHP versions simultaneously
<?php function wp_create_links( $link_data ) { $links = array(); if ( isset( $link_data ) && is_array( $link_data ) ) { foreach ( $link_data as $key => $link ) { $attributes = array(); if ( isset( $link['attributes'] ) && is_array( $link['attributes'] ) ) { $attributes = $link['attributes']; } // URL check. if ( empty( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) { continue; } // Label check. if ( empty( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) { continue; } // Current check. if ( ! empty( $link['is_current'] ) && true === $link['is_current'] ) { $attributes['aria-current'] = 'page'; if ( empty( $attributes['class'] ) ) { $attributes['class'] = 'current'; } else { $attributes['class'] .= ' current'; } } // Collapse attributes to attribute="value" or boolean attributes. $attributes = array_map( function( $attribute, $value ) { // Mark invalid/empty attributes for removal. if ( empty( $attribute ) || ! is_string( $attribute ) ) { return false; } // Convert `int` and `float` values to `string`. if ( is_int( $value ) || is_float( $value ) ) { $value = (string) $value; } // Mark non-string values for removal. if ( ! is_string( $value ) ) { return false; } // On an empty `value`, assume this is a boolean attribute. if ( empty( $value ) ) { return $attribute; } return sprintf( '%s="%s"', $attribute, $value ); }, array_keys( $attributes ), array_values( $attributes ) ); // Clean up attributes. $attributes = array_filter( $attributes ); // Generate link. $links[ $key ] = sprintf( '<a href="%s"%s>%s</a>', $link['url'], ! empty( $attributes ) ? ' ' . implode( ' ', $attributes ) : '', $link['label'] ); } } return $links; } // Usage $links_data = array( 'my_link' => array( 'url' => 'https://example.org', 'label' => 'My Example Link', 'is_current' => true, 'attributes' => array( 'class' => 'menu-link', 'rel' => 'author me', ), ), 'my_other_link' => array( 'url' => 'https://example.com', 'label' => 'My Other Example Link', 'is_current' => true, 'attributes' => array( 'class' => 'menu-link', 'rel' => 'noreferer', ), ), ); $links = wp_create_links( $links_data ); // Want to wrap them? foreach ( $links as $id => $link ) { printf( '<li id="%s">%s</li>', $id, $link ); echo "\n"; }
Output for git.master, git.master_jit
<li id="my_link"><a href="https://example.org" class="menu-link current" rel="author me" aria-current="page">My Example Link</a></li> <li id="my_other_link"><a href="https://example.com" class="menu-link current" rel="noreferer" aria-current="page">My Other Example Link</a></li>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
19.7 ms | 409 KiB | 5 Q