|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PHP trim array function
I could have sworn there was a function to be used on arrays that would remove all empty elements. I know it isn't called trim, but I thought I have seen it before, but can't find it. Maybe I am imagining things. This is what I am looking for it to do.
$test_array('foo', 'bar', '', 'sleep', ''); after going through the function it the array would be $test_array('foo', 'bar', 'sleep'); I know writing a function isn't that hard and I come across needing this at different times for different sites so I was just wanting to know if somebody else knows if this function exists. |
|
#2
|
||||
|
||||
|
Found it.
|
|
#3
|
||||
|
||||
|
there isn't a built in function (check for yourself if you don't believe me: http://php.net/array ), but you can make one:
PHP Code:
PHP Code:
PHP Code:
__________________
If you are using PHP please use the [php] and [/php] forum tags for highlighting... The same applies to HTML and the forums [html][/html] tags. |
|
#4
|
||||
|
||||
|
I found this thread
http://www.webdeveloper.com/forum/sh...d.php?t=185855 |
|
#5
|
||||
|
||||
|
Did you see the use notes on the man page?
http://us.php.net/manual/en/function.array-filter.php It looks like you're using alpha values in your array but be aware it'll remove anything that factors to false or zero. If that what you want then cool. |
|
#6
|
||||
|
||||
|
Quote:
__________________
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ Terry Pratchett in Nation Kindle Minds (blog about Amazon Kindle) |
|
#7
|
||||
|
||||
|
yea, just wanted to bring it to attention. It's a neat function.
__________________
Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience. |
|
#8
|
||||
|
||||
|
It works like a charm. Great function.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|