search
Homephp教程PHP源码按照RATE修改变量或数组单元的值

按照RATE修改变量或数组单元的值

<?php

/**
 * 按照RATE修改变量或数组单元的值
*
 * @author yearnfar
*/

define(&#39;RATE&#39;, 0.5);

function affectNumber(&$number1, &$number2=0, &$number3=0, &$number4=0, &$number5=0)
{
$count = func_num_args();
if ($count<1 || $count>5) {
exit("param error!");
}

for ($i=1; $i<=$count; $i++) {
$varname = &#39;number&#39;.$i;
$$varname = $$varname * RATE;
}
}

// 例子1
$a = 80;
$b = 90;
$c = 100;

affectNumber($a, $b, $c);

echo $a."rn";
echo $b."rn";
echo $c."rn";

function affectArray(&$arr)
{
$args = func_get_args();
if (empty($args)) {
exit("param error!");
}
array_shift($args);

foreach ($arr as $key => $value) {
if (empty($args) || in_array($key, $args)) {
$arr[$key] = $value * RATE;
}
}
}

//例子2
$arr = array(80, 90, 100);

affectArray($arr, 0, 2);

print_r($arr);
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.