Re: [PHP] Emptying a Single Array Value

2002-06-12 Thread Kevin Stone

Note: using unset alone you will end up with an array containing
non-contiuguous indicies.  For the most part this is not a problem but in
some cases can cause trouble.  I'd suggest passing through the
array_values() function to reindex the array after you have unset all of the
unwanted elements.

To count the number of elements in an array using the count() function..
$size = count($array);

-Kevin

- Original Message -
From: "Martin Clifford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, June 12, 2002 1:10 PM
Subject: Re: [PHP] Emptying a Single Array Value


> I have an online example of the progam at
http://www.recordconsulting.com/temp/shop.php.  Each of the delete links use
the corresponding index values for the array, and use the unset() function
to remove them.
>
> While I'm here... how do I find the amount of information in an array?
JavaScript parlance would be $array.length.
>
> Code is below:
>
> 
> 
> if($action == "delete") {
> unset($item[$id]);
> }
>
> $color = "#336699";
>
> var_dump($item);
>
> for($counter = 0; $counter < 7; $counter++) {
> $offset = $counter + 1;
> echo "\n";
> echo "Item " . $offset . ": " . $item[$counter];
> echo "\n";
> echo "\n";
> echo "Delete\n";
> echo "\n\n";
>
> if($color == "#336699") {
> $color = "#6699CC";
> } else {
> $color = "#336699";
> }
> }
>
> ?>
> 
>
> Thanks!
>
> >>> Philip Olson <[EMAIL PROTECTED]> 06/12/02 03:02PM >>>
>
> unset() works for this, how are you using it
> exactly?  Please post a short test script
> that misbehaves for you.
>
>   $arr = array('foo','bar');
>   unset($arr[0]);
>
>   print_r($arr); // only $arr[1] = 'bar' exists now
>
> See also: http://www.php.net/unset
>   http://www.php.net/array_splice
>
> Regards,
> Philip Olson
>
>
> On Wed, 12 Jun 2002, Martin Clifford wrote:
>
> > Howdy,
> >
> > If someone out there could tell me how to get rid of a single key/index
pair within an array, it would be great.  I've tried both unset() and
empty(), but both destroy the entire array.
> >
> > Please CC me directly, as I'm on the digest.
> >
> > Thanks in advance!
> >
> > Martin
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Emptying a Single Array Value

2002-06-12 Thread Martin Clifford

I have an online example of the progam at 
http://www.recordconsulting.com/temp/shop.php.  Each of the delete links use the 
corresponding index values for the array, and use the unset() function to remove them.

While I'm here... how do I find the amount of information in an array?  JavaScript 
parlance would be $array.length.

Code is below:


\n";
echo "Item " . $offset . ": " . $item[$counter];
echo "\n";
echo "\n";
echo "Delete\n";
echo "\n\n";

if($color == "#336699") {
$color = "#6699CC";
} else {
$color = "#336699";
}
}

?>


Thanks!

>>> Philip Olson <[EMAIL PROTECTED]> 06/12/02 03:02PM >>>

unset() works for this, how are you using it 
exactly?  Please post a short test script 
that misbehaves for you.

  $arr = array('foo','bar');
  unset($arr[0]);

  print_r($arr); // only $arr[1] = 'bar' exists now

See also: http://www.php.net/unset 
  http://www.php.net/array_splice 

Regards,
Philip Olson


On Wed, 12 Jun 2002, Martin Clifford wrote:

> Howdy,
> 
> If someone out there could tell me how to get rid of a single key/index pair within 
>an array, it would be great.  I've tried both unset() and empty(), but both destroy 
>the entire array.
> 
> Please CC me directly, as I'm on the digest.
> 
> Thanks in advance!
> 
> Martin
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php 
> 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Emptying a Single Array Value

2002-06-12 Thread Kevin Stone

$nums = array ('one', 'two', 'three');
$nums = remove_array_element($nums, 1);

function remove_array_element($array, $index)
{
unset($array[$i]);  // Unset selected index
return array_values($array); // Return reindexed array
}

P.S. The empty() function returns true or false depending upon whether or
not the variable you pass to contains information, it doesn't affect the
variable.

-Kevin

- Original Message -
From: "Martin Clifford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 12, 2002 12:48 PM
Subject: [PHP] Emptying a Single Array Value


> Howdy,
>
> If someone out there could tell me how to get rid of a single key/index
pair within an array, it would be great.  I've tried both unset() and
empty(), but both destroy the entire array.
>
> Please CC me directly, as I'm on the digest.
>
> Thanks in advance!
>
> Martin
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Emptying a Single Array Value

2002-06-12 Thread Philip Olson


unset() works for this, how are you using it 
exactly?  Please post a short test script 
that misbehaves for you.

  $arr = array('foo','bar');
  unset($arr[0]);

  print_r($arr); // only $arr[1] = 'bar' exists now

See also: http://www.php.net/unset
  http://www.php.net/array_splice

Regards,
Philip Olson


On Wed, 12 Jun 2002, Martin Clifford wrote:

> Howdy,
> 
> If someone out there could tell me how to get rid of a single key/index pair within 
>an array, it would be great.  I've tried both unset() and empty(), but both destroy 
>the entire array.
> 
> Please CC me directly, as I'm on the digest.
> 
> Thanks in advance!
> 
> Martin
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Emptying a Single Array Value

2002-06-12 Thread Damian Harouff

This is all i've ever been able to do:

function ck_removeValueFromArray($array, $value) {

$key = array_search($value, $array);

if ($key) {

$array[$key] = "";
rsort($array); // rsort() puts blank values at the end
reset($array);
array_pop($array); //use array_pop to remove the blank


}

return $array;

}

MC> Howdy,

MC> If someone out there could tell me how to get rid of a single key/index pair 
within an array, it would be great.  I've tried both unset() and empty(), but both 
destroy the entire array.

MC> Please CC me directly, as I'm on the digest.

MC> Thanks in advance!

MC> Martin


MC> --
MC> PHP General Mailing List (http://www.php.net/)
MC> To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Emptying a Single Array Value

2002-06-12 Thread Martin Clifford

Howdy,

If someone out there could tell me how to get rid of a single key/index pair within an 
array, it would be great.  I've tried both unset() and empty(), but both destroy the 
entire array.

Please CC me directly, as I'm on the digest.

Thanks in advance!

Martin


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php