homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
change array values
ahmed24

5+ Year Member



 
Msg#: 3987304 posted 1:25 pm on Sep 10, 2009 (gmt 0)

i have an array that looks like this:

$columns = Array
(
[82] => Monday
[91] => Wednesday
[88] => Friday
);

i want to be able to dynamically remove values from $columns if it is Wednesday and then have a new array set called $columns_filtered with the Wednesday value deleted

can anyone please tell me how i can do this?

thanks

 

ahmed24

5+ Year Member



 
Msg#: 3987304 posted 3:39 pm on Sep 10, 2009 (gmt 0)

i have figured out that i can use unset to remove lines of an array like this:

unset($columns[82]);

this works fine, but what i want to know is if there is anyway to unset it based on the name like for example:

unset($columns[Wednesday]);

ahmed24

5+ Year Member



 
Msg#: 3987304 posted 3:51 pm on Sep 10, 2009 (gmt 0)

i think i have figured it out, i am going to try using array_search to search for the word e.g. wednesday and return the corresponding key

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 3987304 posted 5:43 pm on Sep 10, 2009 (gmt 0)

Sorry for the late reply ahmed24, but I think what you want here is array_slice() [us3.php.net] or array_splice() [us3.php.net], depending on which works best for your conditions.

Splice actually removes the elements, so this is probably the one you want.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved