How to change the value of a two-dimensional array in php

藏色散人
Release: 2023-03-03 11:56:01
Original
2731 people have browsed it

How to change the array value in php: 1. Modify the value of the array in the form of "for($i = 0; $i < count(Array()); $i)"; 2. Use The "oreach($users as &$user)" method changes the value of the array.

How to change the value of a two-dimensional array in php

Recommended: "PHP Tutorial"

PHP Modify the value in the array

①. The two-dimensional array can be modified in the form of for($i = 0; $i < count(Array()); $i)

Example code :

// 修改 二维数组中的 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);
Copy after login

②. The two-dimensional array can also be modified in the form of foreach($users as &$user)

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);
Copy after login

The above is the detailed content of How to change the value of a two-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!