你好,我有一个多维数组,每个数组都包含"id_category"键
我试图在多维数组中循环存储键"id_category"的值。
这里是数组& php编译器
$save_id_category = [];
foreach($array as $ct){
$save_id_category[] = $ct['id_category'];
}
print_r($save_id_category); // this gets me only one record.
我可以循环遍历所有数组&保存数据,但这不是个好主意。
如果我们
我有一个多维锯齿字符串数组:
string[,][] MDJA =
{
{new string[]{"a", "b"}, new string[]{"c", "d"}, new string[]{"e", "f"}},
{new string[]{"g", "h"}, new string[]{"j", "i"}, new string[]{"k", "l"}},
{new st
我编写了以下扩展以从Array中删除重复项。
extension Array where Element : Equatable{
func removeDups() -> [Element]{
var result = [Element]()
for element in self{
if !result.contains(element){
result.append(element)
}
}
return result
我试图实现检查我的数组是否有重复的项。但在我的特殊情况下,我需要使用二维数组。
对于一个包含10个项的数组,我成功地构建了这段代码,并存储了需要验证的值,这些值是否具有重复的值:$array[0][0]、$array[1][0]、$array[2][0].
$arrayItemCount = 10; //means $array[0][0] to $array[9][0]
for ($p=0;$p<$arrayItemCount;$p++){
for ($h=0;$h<$arrayItemCount;$h++){
if ($array