replace a array value

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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

replace a array value

Post by dull1554 »

say i have this array

Code: Select all

Array
(
   [0] => one
   [1] => two
   [2] => three
   [3] => four
   [4] => five
   [5] => six
)
how would i replace the value of array['2'] with 3 ??????
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i got it, it was answered elsewhere
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You haven't given the array a name so I'm a bit confused.

Code: Select all

<?php

$myArray = array("one","two","three","four","five","six");

// Change value [2] to 3
$myArray[2] = 3;

// OR... Give value [2] the value of [3]
$myArray[2] = $myArray[3];

?>
Hope that helps.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

well its ok i really was not thinking, but i got it now, thanks Gen-ik
Post Reply