I have a key that appears to be an empty string, however using unset($array[""]);
does not remove the key/value pair. I don't see another function that does what I want, so I'm guessing it's more complicated that just calling a function.
The line for the element on a print_r is [] => 1
, which indicates to me that the key is the empty string.
Using var_export, the element is listed as '' => 1
.
Using var_dump, the element is listed as [""]=>int(1)
.
So far, I have tried all of the suggested methods of removal, but none have removed the element. I have tried unset($array[""]);
, unset($array['']);
, and unset($array[null]);
with no luck.
Try unset($array[null]);
If that doesn't work, print the array via var_export
or var_dump
instead of print_r
, since this allows you to see the type of the key. Use var_export
to see the data in PHP syntax.
var_export($array);
Note that var_export does not work with recursive structures.
Tried:
$someList = Array('A' => 'Foo', 'B' => 'Bar', '' => 'Bah');
print_r($someList);
echo '<br/>';
unset($someList['A']);
print_r($someList);
echo '<br/>';
unset($someList['']);
print_r($someList);
echo '<br/>';
Got:
Array ( [A] => Foo [B] => Bar [] => Bah )
Array ( [B] => Bar [] => Bah )
Array ( [B] => Bar )
You should analyse where the key come from, too...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With