我不是 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';
更多信息:
关于php 数组(并删除某些元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3342999/