|
|
|
|
![]() ![]() |
Feb 10 2008, 11:14 AM
Post
#1
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 680 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
I have an index array
CODE $array[0] = 10; $array[1] = 12; ... Its kinda late and I'm falling asleep now but I had a quick look through PHP.net, and could not find what I'm after, Maybe I'm too sleepy, sorry, but if anyone knows off the top of their head a way to removed members in that array based on its value, i.e. I wanna remove values 12. I don't really want to do a loop but if I cant find any existing function to do it, then I may have to. Thanks for any help. |
|
|
|
Feb 10 2008, 05:36 PM
Post
#2
|
|
|
Ephesians 6:10-17 ![]() Group: [MODERATOR] Posts: 1,893 Joined: 22-June 05 From: The World of Gentoo Member No.: 8,528 ![]() |
You may have to make your own function or set up for this. But i did a quicky function that should work fine for your needs:
CODE function remove_element($arr, $val){ foreach ($arr as $key => $value){ if ($arr[$key] == $val){ unset($arr[$key]); } } return $arr = array_values($arr); } You can rename the function if you want. |
|
|
|
Feb 10 2008, 08:00 PM
Post
#3
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 680 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
Thanks again for the help Truefusion. Its too bad PHP does not have a array function for this specific task itself, they seem to have many other functions for other kinds of array modifications.
|
|
|
|
Mar 16 2008, 02:04 AM
Post
#4
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
thanks
Remove A Value From A Php Array Based On Its Value Replying to truefusion This is really good... I needed a script to find the only file in a folder, but it returned '.' and '..' and then the file... Now I just do this: <?php $return = delete_value($return, '.'); $return = delete_value($return, '..'); ?> Thanks... -reply by php-freak! |
|
|
|
Mar 19 2008, 09:29 PM
Post
#5
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
strip element from array()
Remove A Value From A Php Array Based On Its Value Replying to truefusion Is there away to chop an array depending on the value of a sub-array? I.E: $array[0] = 10; $array[1] = 12; $allcontent = array("page1", "page2", array("page3a", "page3b"), "page4", "page5"); If my function finds "page3b" I want it to end the parent array at "page2"/ I.E.: $allcontent = array("page1", "page2"); If this can't be done how about just removing the sub array? I.E.: $allcontent = array("page1", "page2", "page4", "page5"); -reply by Scoutman57 |
|
|
|
Jun 10 2008, 04:09 AM
Post
#6
|
|
|
Trap Double Mocha Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th September 2008 - 11:11 PM |