Home>Article>Backend Development> How to modify the contents of a two-dimensional array in php

How to modify the contents of a two-dimensional array in php

L
L Original
2020-06-01 09:17:18 3182browse

How to modify the contents of a two-dimensional array in php

PHP Modify the values in the two-dimensional array

1. The two-dimensional array can be passed through for($i = 0; $i < count(Array()); $i) This form modifies the

example code:

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

2. Two-dimensional arrays can also be passed in the form of foreach($users as &$user) Modify

Instance code

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

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to modify the contents of a two-dimensional 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