Home > Article > Backend Development > How to modify array value in php
php method to modify the array value: 1. Modify through statements, the code is [for($i = 0; $i < count(Array()); $i)]; 2. Two-dimensional array Implemented through the function foreach, the code is [foreach($users as &$user)].
【Related learning recommendations: php graphic tutorial】
How to modify the array value in php:
①. The two-dimensional array can be modified by for($i = 0; $i < count(Array()); $ i)
Modify the
example code in this form:
// 修改 二维数组中的 name为 Getchar $users = array( array(‘name‘ => ‘GetcharZp‘, ‘age‘ => 19), array(‘name‘ => ‘Mcx‘, ‘age‘ => 18) ); for ($i = 0; $i < count($users); ++ $i) { $users[$i][‘name‘] = ‘Getchar‘; } print_r($users);
②, the two-dimensional array can also be passed foreach($users as &$user)
Form modification
Example code
// 修改 二维数组中的 name为 Getchar $users = array( array(‘name‘ => ‘GetcharZp‘, ‘age‘ => 19), array(‘name‘ => ‘Mcx‘, ‘age‘ => 18) ); foreach ($users as &$user) { $user[‘name‘] = ‘Getchar‘; } print_r($users);
If you want to know more related learning, please pay attention to the php training column!
The above is the detailed content of How to modify array value in php. For more information, please follow other related articles on the PHP Chinese website!