return $this->array_to_code_string( $items, $quotes );
}
/**
* Takes an array of strings and returns php code for an array of strings.
*
* @param string[] $items The array to convert.
* @param bool $quotes Whether to add quotes to the values or not.
*
* @return string
*/
public function array_to_code_string( $items, $quotes = true ) {
if ( empty( $items ) || empty( $items[0] ) ) {
return 'array()';
}
$items = array_map( 'trim', $items );
if ( $quotes ) {
$items = array_map( array( $this, 'add_quotes' ), $items );
}
return 'array( ' . implode( ', ', $items ) . ' )';
}
/**
* Callback to add quotes because we can't use closures in PHP 5.2.
*
* @param string $item String to add quotes to.
*
* @return string
*/
private function add_quotes( $item ) {
return "'$item'";
}
POC๏ผ