在 PHP 中,要向数组中添加一个值,可以使用以下方式:
- 使用
array_push() 函数:$fruits = ['apple', 'banana', 'orange'];array_push($fruits, 'grape');- 直接给数组赋值:
$fruits = ['apple', 'banana', 'orange'];$fruits[] = 'grape';- 使用指定键名添加值:
$fruits = ['a' => 'apple', 'b' => 'banana'];$fruits['c'] = 'cherry';无论使用哪种方法,添加值后,数组将会包含新的值。
上一篇:python的sleep函数无法唤醒怎么解决
下一篇:c++中的wait_for函数有什么作用
php









