PHP 将值推入关联数组?
若要将值推入关联数组,请使用方括号 [] []。首先创建一个关联数组 -
$details= array ( 'id' => '101', 'name' => 'John Smith', 'countryName' => 'US' );
以下 PHP 代码用于插入值 -
示例
<!DOCTYPE html> <html> <body> <?php $details= array ( 'id' => '101', 'name' => 'John Smith', 'countryName' => 'US' ); $all_details['studentDetails'][] = $details; print_r($all_details); ?> </body> </html>
输出
Array ( [studentDetails] => Array ( [0] => Array ( [id] => 101 [name] => John Smith [countryName] => US ) ) )
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP