sonesay
Feb 10 2008, 11:14 AM
| | 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. |
Reply
truefusion
Feb 10 2008, 05:36 PM
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.
Reply
sonesay
Feb 10 2008, 08:00 PM
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.
Reply
iGuest
Mar 16 2008, 02:04 AM
thanks
Remove A Value From A Php Array Based On Its Value
Replying to truefusionThis 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!
Reply
iGuest
Mar 19 2008, 09:29 PM
strip element from array()
Remove A Value From A Php Array Based On Its Value
Replying to truefusionIs 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
Reply
iGuest
Jun 10 2008, 04:09 AM
Replying to sonesayA. $key = array_search() B. Unset($key)
Reply
Recent Queries:--
php array how to add and remove - 9.65 hr back. (1)
-
php delete from array - 12.41 hr back. (2)
-
how to remove a value from array - 14.62 hr back. (1)
-
remove value from middle of array - 16.50 hr back. (1)
-
remove value from array php - 21.33 hr back. (1)
-
remove an array in session using php - 23.78 hr back. (1)
-
remove values < 0 from array php - 25.29 hr back. (1)
-
php find and remove object from array - 31.94 hr back. (1)
-
remove value from array - 36.24 hr back. (1)
-
array remove based on value - 37.21 hr back. (1)
-
php array delete - 40.05 hr back. (1)
-
remove specific element array php - 40.15 hr back. (1)
-
remove from array php - 41.31 hr back. (1)
-
php remove from array - 13.40 hr back. (3)
Similar Topics
Keywords : remove php array based- Sending E-mails Based On Intervals?
- (7)
- Creating Something With Co-ordinates With Php.
- Something like you see in those web-based php games, like a map or som (12)
Well, i was just wondering if something simple and basic could be made (like a small map where you
could move around on, like you click up, and your position moves up and reports it to the
database..etc) with co-ordinates in php . Taking the x-axis and the y-axis into consideration.
Things like maps which online games have such as web-based space games or legacy-game.net. Thanks
for any feedback, ~Aldo...
Looking For Command Line Based Sql Modification
- Program Needed For SQL? (1)
How I use Windows command prompt client and do modifications to my SQL database. If yes, please
write the commads I should know for that. If no, please get me the software with which I can do it.
Topic title modified. Proper English is always required when posting in our forum. ...
Php And Irc
- PHP-based IRC web client (5)
I am wondering whether or not you could create a basic client for IRC using PHP. I know that PHP
does have IRC functions which I read about on php.net. I am not quite sure whether or not a client
could be built around this. I do know that there is a CGI IRC client on the web. I use this while I
am on my Wii I am wanting to incorporate a PHP IRC client into my website and use AJAX to
automatically reload the chat. Well, if anybody could help that would be great....
Getting An Array Value Of A Dynamic Variable
- (9)
Ok i can't believe I need help in php but I can't figure this out... If i have an array,
lets say called test, how do i get a certain value from that array when referencing it dynamically
by either a string or another variable? Example: CODE $test=array(1,2,5);
$name="test"; //Doesn't work: echo $$name[0]; /Doesn't
work: echo ${$name}[0]; ...
Dynamically Select From 2 Tables Based On Id
- dynamically select from 2 tables based on id (1)
hi there, im working on a performance request system, and i have three tables that im working with
right now. the performances table holds the info about the performance (date, times, status, etc.),
and has two columns, org_type and org_id, which both hold an int value to tell me where the
organization info is. there are two org types which have respective tables, because we collect
different information based on the type of org that is registering. is there any way to select info
from all three tables (dynamically selecting between the two org tables based on org_type,...
Using Multiple Selection Array In Table To Order Data
- Using multiple selection array in table to order data (1)
have a form that has a multiple select choice, like this: CODE <form method="post"
action="display.php" <select multiple name="selectsort[]">
<option value="code">Code</option> <option
value="amount">Amount</option> <option value="dateammended">Date
Ammended</option> <option value="expreviewdate">Expiration/Review
Date</option> <option value="effectivedate">Effective Date</option>
<option value="e...
Reading Files From Directory To Array, And Using $_get To Get Them
- Simple way to manage lot's of files (2)
Some user posted a similar problem i had when i tried to figure out how to update content on my
website in less work as possible. This is just part of the "big" plan i have for my site but it can
be helpfull to you guys if you like FlatFile. I hope that mod's don't mind me posting the
same code here and on their forums, couse if they do i'll delete it from their forums
/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So
here's the situation. Let's say you have a folder called 'myfilesdirectory' on your
s...
More Dynamic ?id=browsing With Php (associative Array)
- Just create array and watch php code do the rest (1)
The thing that has been bugging me for a while was that switch statement that we use to create ID
browsing (some use If-Ifelse but results are the same for both). I wanted to figure out a way to use
more dynamic switch statement so that i only need to update my links array in order to create links
for template. With use of foreach, array_keys, and in_array functions finally i managed to do so.
Also i'm planing on changing foreach with array_walk but i'll do that later. Now for the
code.. First we create an associative array something like this CODE $gl...
Remove Unnecessary Decimals With Php?
- (3)
I have a MySQL DECIMAL field allowing up to 3 decimals to the number. However, many of the numbers
only have one decimal. An example is 5.2. I want the script to echo ONLY 5.2 and not 5.200. However,
if the number is 5.211, I want it to echo the whole number, so I can't just use the round()
function. Is there a way to do this?...
Spliting An Array
- (4)
I got this excercise from school, im trying to understand it but im unable..can someone help me ?its
very small problem but im not getting the point. ------------------ Create a string:
$wholestring = “splitwholestring”; And split it to array using for loop. So that you have a
array containing all the letters of the string: array == s, array == p, etc. Display results.
(hint: strlen(), substr() - functions are useful) ------------------...
Converting Characters In A Variable To Individual Values In An Array
- turning variables into arrays (2)
Say I have a variable such as $nav_item and it had to contents Home . IE: CODE
$nav_item = 'Home'; How would I make so that $nav_item was an array and
had the following contents? CODE $nav_item = array ('h', 'o',
'm', 'e'); With the case changing (ie H would become h and U
would become u ) EDIT: Okay found out that I could change the case with
array_change_key_case ($nav_item, CASE_LOWER); ...
Remove Objects From Array With Unset
- (2)
Have been trying to solve this for a long time now, so I thought I´d give you guys a chance to break
it! I want to remove an object from an array that I store in a Session object. I´ve written a
function that takes an array and an id as parameters. Checks if one of the objects has the id I want
to remove and then it´s supposed to remove it. Quite simple, that´s why I cant see why it doesnt
work! Here´s the code: CODE function Remove_prod($id2,$AL) {
print_r($AL); foreach ($AL as $prod) if($prod-...
Looking for remove, php, array, based
|
|
Searching Video's for remove, php, array, based
|
advertisement
|
|