Re: Modifying arrays

From: Date: Mon, 15 Jan 2001 14:47:26 +0000
Subject: Re: Modifying arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-34620@lists.php.net to get a copy of this message
try this one.. seems to easy though. Maybe I'm missing something?? <? /* throw a few values into an array */ $my_arr[1]= "ichi"; $my_arr[2]= "ni"; $my_arr[3]= "san"; $my_arr[4]= "shi"; $my_arr[5]= "go"; /* set a variable equal to the current value in the array using pos() */ $curr_val = pos($my_arr); /* set another variable equal to the current key in the array using key() */ $curr_key = key($my_arr); /* for debug's sake, print the variables out */ print($curr_val."\n"); /* returns "ichi" */ print($curr_key."\n"); /* returns "1" */ /* now, use that key variable to change the current value */ $my_arr[$curr_key] = "one"; /* now, reprint the key directly from the array to show it's changed */ print($my_arr[$curr_key]."\n"); ?> Cheers, Brad On Mon, 15 Jan 2001, Catalin Borcea wrote: > How do I modify the value of the current element of an array? > > -- Catalin Borcea -- > \\\|/// > \\ - - // > ( @ @ ) > -----oOOO----(_)----OOOo---- > > > > >

« previous php.general (#34620) next »