请问一个数据替换的有关问题

WBOY
Release: 2016-06-13 13:44:01
Original
678 people have browsed it

请教一个数据替换的问题
我有很多组数据

1, 2, 5, 6, 7

2, 5, 6, 7, 8

1, 2, 4, 6, 9

...//更多数据

我想把这里的数据都按下面规则转换

1转换成 91
2转换成 93
3转换成 87
4转换成 78
5转换成 61
6转换成 53
7转换成 90
8转换成 60
9转换成 95

最后数据变成
91, 93, 61, 53, 90

93, 61, 53, 90, 60

91, 93, 78, 53, 95

...

请问这个该怎么写呢?


------解决方案--------------------

PHP code

<?php $arr_0 = array(1,2,5,6,7);
    $arr_1 = array(2,5,6,7,8);
    $arr_2 = array(1,2,4,6,9);
    $arr = array($arr_0,$arr_1,$arr_2);
    if(!empty($arr)){
        for($i = 0; $i < count($arr); $i++){
            for($j = 0; $j < count($arr[0]); $j++){
                switch ($arr[$i][$j]) {
                    case '1': $arr[$i][$j] = '91';
                    break;
                    case '2': $arr[$i][$j] = '93';
                    break;
                    case '3': $arr[$i][$j] = '87';
                    break;
                    case '4': $arr[$i][$j] = '78';
                    break;
                    case '5': $arr[$i][$j] = '61';
                    break;
                    case '6': $arr[$i][$j] = '53';
                    break;
                    case '7': $arr[$i][$j] = '90';
                    break;
                    case '8': $arr[$i][$j] = '60';
                    break;
                    case '9': $arr[$i][$j] = '95';
                    break;
                }
            }
        }
    }
?> <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
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