search
HomeBackend DevelopmentPHP Tutorial请问一个数据替换的有关问题

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

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>
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
counta和count的区别counta和count的区别Nov 20, 2023 am 10:01 AM

Count函数用于计算指定范围内数字的个数。它忽略文本、逻辑值和空值,但会将空单元格计算在内,Count函数只计算包含实际数字的单元格数量。而CountA函数用于计算指定范围内非空单元格的个数。它不仅计算包含实际数字的单元格,还计算包含文本、逻辑值和公式等非空单元格的数量。

使用C#中的Array.Sort函数对数组进行排序使用C#中的Array.Sort函数对数组进行排序Nov 18, 2023 am 10:37 AM

标题:C#中使用Array.Sort函数对数组进行排序的示例正文:在C#中,数组是一种常用的数据结构,经常需要对数组进行排序操作。C#提供了Array类,其中有Sort方法可以方便地对数组进行排序。本文将演示如何使用C#中的Array.Sort函数对数组进行排序,并提供具体的代码示例。首先,我们需要了解一下Array.Sort函数的基本用法。Array.So

HMD Skyline gets a new color option and official magnetic caseHMD Skyline gets a new color option and official magnetic caseAug 23, 2024 am 07:04 AM

When the HMD Skyline(available on Amazon for $499) was launched last month, it was released in two colors - Neon Pink and Twisted Black. They are now joined by a third color dubbed Blue Topaz. HMD Global has also announced an official case for the ph

简单明了的PHP array_merge_recursive()函数使用方法简单明了的PHP array_merge_recursive()函数使用方法Jun 27, 2023 pm 01:48 PM

在进行PHP编程时,我们常常需要对数组进行合并。PHP提供了array_merge()函数来完成数组合并的工作,不过当数组中存在相同的键时,该函数会覆盖原有的值。为了解决这个问题,PHP在语言中还提供了一个array_merge_recursive()函数,该函数可以合并数组并保留相同键的值,使得程序的设计变得更加灵活。array_merge

如何使用PHP中的array_combine函数将两个数组拼成关联数组如何使用PHP中的array_combine函数将两个数组拼成关联数组Jun 26, 2023 pm 01:41 PM

在PHP中,有许多强大的数组函数可以使数组的操作更加方便和快捷。当我们需要将两个数组拼成一个关联数组时,可以使用PHP的array_combine函数来实现这一操作。这个函数实际上是用来将一个数组的键作为另一个数组的值,合并成一个新的关联数组。接下来,我们将会讲解如何使用PHP中的array_combine函数将两个数组拼成关联数组。了解array_comb

switch case判断变量switch case判断变量Feb 19, 2024 am 08:04 AM

switchcase判断变量,需要具体代码示例在编程中,我们经常需要根据不同的变量值来执行不同的操作。switchcase语句是一种方便的结构,可以根据变量的值来选择不同的代码块进行执行。下面是一个具体的代码示例,展示了如何使用switchcase语句判断变量的不同取值:#includeintmain(){

PHP array_fill()函数用法详解PHP array_fill()函数用法详解Jun 27, 2023 am 08:42 AM

在PHP编程中,数组是一种非常重要的数据结构,能够轻松地处理大量数据。PHP中提供了许多数组相关的函数,array_fill()就是其中之一。本篇文章将详细介绍array_fill()函数的用法,以及在实际应用中的一些技巧。一、array_fill()函数概述array_fill()函数的作用是创建一个指定长度的、由相同的值组成的数组。具体来说,该函数的语法

Python中的Array模块怎么使用Python中的Array模块怎么使用May 01, 2023 am 09:13 AM

Python中的array模块是一个预定义的数组,因此其在内存中占用的空间比标准列表小得多,同时也可以执行快速的元素级别操作,例如添加、删除、索引和切片等操作。此外,数组中的所有元素都是同一种类型,因此可以使用数组提供的高效数值运算函数,例如计算平均值、最大值和最小值等。另外,array模块还支持将数组对象直接写入和读取到二进制文件中,这使得在处理大量数值数据时更加高效。因此,如果您需要处理大量同质数据,可以考虑使用Python的array模块来优化代码的执行效率。要使用array模块,首先需要

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function