温馨提示×

使用PHP字典处理数据的示例

PHP
小樊
82
2024-07-13 03:03:21
栏目: 编程语言

// 创建一个关联数组来存储数据 $data = array( “name” => “John”, “age” => 30, “city” => “New York” );

// 输出数组中的某个值 echo "Name: " . $data[‘name’] . “
”; echo "Age: " . $data[‘age’] . “
”; echo "City: " . $data[‘city’] . “
”;

// 修改数组中的某个值 $data[‘age’] = 31;

// 输出修改后的值 echo "Updated age: " . $data[‘age’] . “
”;

// 遍历整个数组并输出键值对 foreach ($data as $key => $value) { echo $key . ": " . $value . “
”; }

0