php 数组(并删除某些元素)

标签 php arrays

我不是 100% 但这个 ($settings) 在 php 中将被称为数组:

$setting;

$setting['host'] = "localhost";
$setting['name'] = "hello";

但是这个与上面不同的名称是什么:

$settings = array("localhost", "hello");

另外,在第一个示例中,我如何删除名为 name 的元素?

(如果我犯了错误,还请纠正我的术语)

最佳答案

I'm not 100% but this ($settings) would be called an array in php:

你应该百分百确定,他们是:)

but what's the name for this that's different to the above:

这个:

$setting['host'] = "localhost";
$setting['name'] = "hello";

这是声明 php 数组的不同方式。

$settings = array("localhost", "hello");

事实上,这就是稍后将第一个与键匹配的方式:

$settings = array("host" => "localhost", "name" => "hello");

Also from the first example how can i remove the element called name?

您可以使用 unset 删除:

unset($setting['name']);

请注意,在声明 PHP 数组时,请执行以下操作:

$setting = array();

而不是:

$setting;

另请注意,您可以通过在数组末尾添加后缀 [] 来将信息附加到数组中,例如,要将第三个元素添加到数组中,您可以简单地执行以下操作:

$setting[] = 'Third Item';

更多信息:

http://php.net/manual/en/language.types.array.php

关于php 数组(并删除某些元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3342999/

相关文章:

java - 我如何将 int 链接到字符串数组 java 中的字符串

php - 在 Laravel 中检查请求数组是否为空

javascript - 如何在不创建大长函数的情况下从另一个数组中的数组中删除值?

PHP动态绑定(bind),如何知道从MySQL中选择了多少条结果?

php - Facebook PHP SDK - 如何获取访问 token ?

javascript - Laravel - 选择2 |表单重置时重置选择值

javascript - 如何将输入值添加到数组中

c++ - 递归最大S个整数

php - 带 CKEditor 的文件管理器

php - 如何获得超过 20 个结果,即。 60 将 google place API 与 PHP 结合使用?