Array unset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Array unset

Post by Shendemiar »

Code: Select all

$A = array (
  'Some' => 'zzzz',
  'Thing' => 'SSSS',
  'B' => 
  array (
    '1:1:1' => 0,
    '2:2:2' => 0,
    '3:3:3' => 0,
How come

Code: Select all

$R = $_GET['F']       (='2:2:2')

unset($A['B'][$R]);

var_export $A
...
    '1:1:1' => 0,
    '3:3:3' => 0,
    '' => 0,
Last edited by Shendemiar on Mon Dec 11, 2006 9:20 pm, edited 1 time in total.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Using array pop i can get rid of it, but its weird.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have no idea what problem you are having because you haven't explained anything. Please do so.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I cannot reproduce the "error".

Code: Select all

<?php
$A = array (
		'Some' => 'zzzz',
		'Thing' => 'SSSS',
		'B' =>array (
				'1:1:1' => 0,
				'2:2:2' => 0,
				'3:3:3' => 0
			)
	);

$R = '2:2:2';
unset($A['B'][$R]);
var_export($A);
prints

Code: Select all

array (
  'Some' => 'zzzz',
  'Thing' => 'SSSS',
  'B' => 
  array (
    '1:1:1' => 0,
    '3:3:3' => 0,
  ),
)
User avatar
Ind007
Forum Newbie
Posts: 14
Joined: Fri Dec 01, 2006 12:39 am
Location: India

Post by Ind007 »

To Shendemiar
I think, we cannot expect unset() to make the key value somthing like space or null
Post Reply