【问题标题】:How to unset/remove an array in php如何在php中取消设置/删除数组
【发布时间】:2015-08-18 00:46:12
【问题描述】:

好的,我创建了一个数组,该数组取决于我从 cURL 请求中收到的数据。我使用正则表达式来获取我想要的数据,然后将其放入数组中。但是,每个请求返回的数据都不同。我现在面临的问题在下面的示例中。我似乎有两个数组。一个包含 2 个字符串 - 这很好。但他们其他的是空白/空数组。

当前结构:

array(2) { [0]=> string(1196) "
Please select your address from the list below.
Address 1
Address 2
Address 3
Address 4
Address 5
Address 6
" [1]=> string(1196) "
Different Address 1
Different Address 2
Different Address 3
Different Address 4
Different Address 5
Different Address 6
" } array(0) { }

我的问题是如何删除/取消设置 array(0) { }

【问题讨论】:

  • 似乎附加的空数组是您的第一个 array(2) 的一个单独的非子数组。是这样,还是错字?
  • if(empty($array)){unset($array)}。为什么因为它不是在寻找子数组,而是在寻找一个单独的数组。或者如果你不小心把它弄错了?
  • 不,这不是一个错字...不幸的是
  • 你能试试这个 unset($array[2][0]);

标签: php arrays unset


【解决方案1】:

使用 php 的 unset 函数。 http://php.net/manual/en/function.unset.php

unset($yourArrayName[0]); 

【讨论】:

    【解决方案2】:

    试试这个unset($arrayName[2][0]);

    【讨论】:

    • 不,它似乎没有针对array(0) { }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2019-02-25
    • 2014-02-20
    • 1970-01-01
    • 2017-11-02
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多