Home > Backend Development > PHP Tutorial > PHP custom function recursively replaces the contents of an array

PHP custom function recursively replaces the contents of an array

WBOY
Release: 2016-07-25 09:04:37
Original
870 people have browsed it
  1. /**

  2. desc: recursively replace array contents
  3. link: bbs.it-home.org
  4. date: 2013/2/22
  5. */
  6. function arrContentReplact($array)
  7. {
  8. if(is_array($array))
  9. {
  10. foreach($array as $k => $v)
  11. {
  12. $array[$k] = arrContentReplact($array[$k]);
  13. }
  14. }else
  15. {
  16. $array = str_replace(
  17. array('<', '>'),
  18. array('{', '}'),
  19. $array
  20. );
  21. }
  22. return $array;
  23. }

  24. //调用示例

  25. $arr = array(array("< jbxue1>","< jb2xue>",array("",array(""))),"< jb33xue>","< jbxue44>","< 44jbxue>");
  26. $arr3 = arrContentReplact($arr);
  27. echo "
    ";</li>
    <li>print_r($arr3);</li>
    <li>echo "
    ";
  28. ?>

复制代码


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