Recursive Function

Anonymous

New Member
I have absolutely no idea, so if someone can point me in the right direction, it'd be greatly appreciated.I want to have something like \[code\]<?phpfunction square($num) {// something}name('{3}'); // have this return 9name('{6}'); // have this return 36name('{{{2}}}'); // have this return 256name('{9}{12}'); // have this return 81144name('{{5}}'); // have this return 125name('adscdc{4}{{3}}'); // have this return adscdc1681?>\[/code\]Does anyone have any idea how this can be done? Thanks in advance :)So far, I have:\[code\]<?phpfunction square($text) { $parts = explode('{', $text); foreach($parts as $part) { $piece = explode('}', $part); $text = str_replace('{' . $piece[0] . '}', pow($piece[0], 2), $text); } return $text;}echo square('aasd{3}');?>\[/code\]
 
Back
Top