search
HomeBackend DevelopmentPHP ProblemHow to modify the value in an array in php

How to modify the value in an array in php

Aug 04, 2020 pm 03:37 PM
phpvaluearray

How to modify the values ​​in the array in php: You can use a for loop to modify, such as [for($i = 0; $i

How to modify the value in an array in php

The two-dimensional array can be modified through for($i = 0; $i

(Recommended tutorial: php graphic tutorial)

Code implementation:

// 修改 二维数组中的 name为 Getchar
$users = array(
    array('name' => 'GetcharZp', 'age' => 19),
    array('name' => 'Mcx', 'age' => 18)
);
for ($i = 0; $i < count($users); ++ $i) {
	$users[$i][&#39;name&#39;] = &#39;Getchar&#39;;
}
print_r($users);

Two-dimensional arrays can also be passed through foreach($users as &$user) modified.

(Video tutorial recommendation: php video tutorial)

Code implementation:

// 修改 二维数组中的 name为 Getchar
$users = array(
    array(&#39;name&#39; => &#39;GetcharZp&#39;, &#39;age&#39; => 19),
    array(&#39;name&#39; => &#39;Mcx&#39;, &#39;age&#39; => 18)
);
foreach ($users as &$user) {
	$user[&#39;name&#39;] = &#39;Getchar&#39;;
}
unset($user);
// 销毁掉 user 引用
print_r($users);

The above is the detailed content of How to modify the value in an array in php. 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

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

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.