Jump to content


Photo

[SOLVED] simple array question


  • Please log in to reply
3 replies to this topic

#1 knowram

knowram
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 19 April 2006 - 03:03 PM

I know this is a stupid question. But I just can't seem to find that answer.

Given an array and a variable is there some way to delete that variable from the array no mater where it is located in that array?

I know there must be some easy function for this but I can't seem to find it.

thanks for the help.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 03:13 PM

Use unset()
[a href=\"http://www.php.net/manual/en/function.unset.php\" target=\"_blank\"]http://www.php.net/manual/en/function.unset.php[/a]

~ D Kuang

#3 knowram

knowram
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 19 April 2006 - 04:01 PM

I did find that but I can't seem to figure out how to use it. This is what i am doing.

$x = array (testing, dog, cat, testing2);

$newx = unset($x['testing2']);

That dose not seem to do anything.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 04:08 PM

$x = array (testing, dog, cat, testing2);

print_r($x);

$k = array_search('testing2', $x);
unset($x[$k]);

print_r($x);

// The first print_r 
Array
(
    [0] => testing
    [1] => dog
    [2] => cat
    [3] => testing2
)

// Second print_r
Array
(
    [0] => testing
    [1] => dog
    [2] => cat
)

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users