简体   繁体   English

如何在PHP中取消设置/删除数组

[英]How to unset/remove an array in php

Okay, I have an array that is created dependant on what data I receive back from a cURL request. 好的,我有一个根据我从cURL请求收到的数据创建的数组。 I use a regex expression to grab the data I want and then place it into an array. 我使用正则表达式来获取所需的数据,然后将其放入数组中。 However the data that is returned differs on every request. 但是,每个请求返回的数据都不同。 The problem I am facing now is in the example below. 我现在面临的问题在下面的示例中。 I seem the have two arrays. 我似乎有两个数组。 One containing 2 strings - which is fine. 一个包含2个字符串-很好。 But they other is a blank/empty array. 但是它们另一个是空白/空数组。

Current structure: 当前结构:

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) { }

My question is how would I go around removing/unsetting array(0) { } ? 我的问题是如何解决/取消设置array(0) { }

Use the php unset function. 使用php unset函数。 http://php.net/manual/en/function.unset.php http://php.net/manual/zh/function.unset.php

unset($yourArrayName[0]); 

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM