Implementation of str_repeat function in PHP in JavaScript_PHP tutorial

WBOY
Release: 2016-07-21 16:12:44
Original
830 people have browsed it

There is a function in PHP: String str_repeat($str, num); it is very easy to use.... The following is implemented through js and php simulation.

1: PHP version

Copy code The code is as follows:

/*PHP version implementation*/
function repeat($str, $num){
return implode( $str, array_fill(0, $num+1, '') );
}

2: JavaScript implementation:
Copy code The code is as follows:

/*JavaScript implementation*/
function repeat(str, num ){
return new Array( num + 1 ).join( str );
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313625.htmlTechArticleThere is a function in PHP: String str_repeat($str, num); It is very easy to use....The following Implemented through js and php simulation. 1: PHP version Copy code The code is as follows: /*PHP version implementation*/ function repeat($str...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!