Re: Replacing an element in an array
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Thu, 22 Jan 2009 20:16:28 -0500
laredotornado@xxxxxxxxxxx wrote:
Hi,
I'm using PHP 5. If I have a non-asociative array, that is an array
where the key is the numerical index of the element ...
// For example
$arr = array("Denver", "Chicago", "Seattle", "Austin");
What is the easiest way to replace all instances of an element in the
array with a new element?
Thanks, - Dave
Maybe something like this?
<?php
$arr = array("Denver", "Chicago", "Seattle", "Austin");
$keys = array_keys($arr, "Denver");
if ($keys !== false)
foreach($keys as $key)
$arr[$key] = "San Francisco";
print_r($arr);
?>
Replaces each instance of "Denver" with "San Francisco".
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Replacing an element in an array
- From: Curtis Dyer
- Re: Replacing an element in an array
- References:
- Replacing an element in an array
- From: laredotornado@xxxxxxxxxxx
- Replacing an element in an array
- Prev by Date: Re: Deleting levels/dimensions from an array
- Next by Date: Re: Inappropriate ioctl for device
- Previous by thread: Re: Replacing an element in an array
- Next by thread: Re: Replacing an element in an array
- Index(es):
Relevant Pages
|