Home >Backend Development >PHP Problem >Can php be replaced in a loop?

Can php be replaced in a loop?

藏色散人
藏色散人Original
2021-11-01 10:17:481593browse

php can be replaced in a loop. The method is: 1. Create a PHP sample file; 2. Loop through "for($i=1;$i<=$num;$i){...}" The statement can be replaced.

Can php be replaced in a loop?

The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer

Can php be replaced in a loop?

php can be replaced in a loop.

#php loop replaces the simple implementation method in turn:

$o['des'] = existing employees

, including front-line senior technicians

There are

people for intermediate skilled workers,

junior technicians, and

people for other personnel.

The purpose is to replace all into input boxes

<?php
                                $num = substr_count($o[&#39;des&#39;],&#39;###&#39;); //4
                                $str = $o[&#39;des&#39;];  ---注意$str的位置,在for循环外面
                                for($i=1;$i<=$num;$i++){
                                    $in = "<input type=&#39;text&#39; class=&#39;space&#39; name=&#39;in$i&#39;/>";
                                    $str = preg_replace("/###/","$in",$str,1);   --注意变量名称必须与要查找到字符串变量名一致,因为是循环替换每一个,要变成不同name值。
                                }
                                echo $str;
                            ?>
###The last parameter (N) of preg_replace is to replace several, here I think it needs to be replaced with different names in sequence value, so it is appropriate to replace them one at a time. ###### Recommended learning: "###PHP Video Tutorial###"###

The above is the detailed content of Can php be replaced in a loop?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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