473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How do I find out if any array is empty?

KeredDrahcir
426 256MB
I'm trying the run a function that only executes if an array is empty.
If the array is empty is technically has one element with the value of ''.

Expand|Select|Wrap|Line Numbers
  1. if(array_filter($array))
The above code should tell me if the array has one or more non-empty elements and it works. However although it works, I get this message.

Warning: array_filter() [function.array-filter]: The first argument should be an array in /my server/my site /public_html/my file.php on line 40

If there a solution to this please?
Aug 20 '10 #1
4 1886
dlite922
1,584 Expert 1GB
There's several ways to do this, it all depends on what you array actually looks like. it would have helped if you printed a few example arrays. For example if the array has multiple keys but all with empty-string values, does that count as empty?

Expand|Select|Wrap|Line Numbers
  1. // check if first element is empty. 
  2.  
  3. if($myarr[0]) ...
  4.  
  5. if(strlen($myarr[0]) > 0) ...
  6.  
  7. $foo = array("key1" => '', "key2" => ' ', "key3" => '   ');
  8.  
  9. $bar = trim(implode($foo));
  10. if(empty($bar)) ...
  11.  
  12.  
you should definitely have a look at php's empty function at php.net/empty

Cheers Mate,


Dan
Aug 20 '10 #2
KeredDrahcir
426 256MB
Those suggestions look realy helpful. When I next get back to that probject I'll try them out and let you know.
Thanks.
Aug 23 '10 #3
KeredDrahcir
426 256MB
None of those worked.
I counted the araay and it gave me one, if there was one item there and one (presumably) empty item there, but that item didn't seem to be empty. Although I had a look at the result, it gave me nothing.
Aug 24 '10 #4
zorgi
431 Expert 256MB
array sample and some code of what you done so far would be very helpful here.
Aug 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rahman | last post by:
I know it should be very easy but I am new in ASP so I could not figured out. Here is the simplified version of my code: thePaymentID= request.querystring("IDValue") SQLqueryPayment= "SELECT...
4
by: Mike Charney | last post by:
What is the easiest and simplest way to find out if a table exists in an Access Data Project? (SQL Svr 2000 Standard using MS-Access 2003 for connection.) Mike Charney m charney at dunlap...
5
by: Abdelhalim | last post by:
Hello, I'm using xalan 2.6, and trying to invoke a transformation using XSL file that contains the function "empty", but I'm getting the below exception, I think the empty function is a valid...
2
by: Jazz Kyat | last post by:
Hello, I have a series of arrays that I inserted into a HashSet. Now I want to find out whether a particular array is contained in the set; how do I do that? Here is what the code looks like:...
14
by: Dan Rumney | last post by:
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = ; as opposed to using a constructor...
8
by: Sunny | last post by:
Hi, Can someone tell me, How to redefine array or make array empty or null. Here what I am trying to do. var temp = new Array(); for(i=0; i <=outstring.length-1; i++) { temp =...
3
by: JFKJr | last post by:
Hello Guys, I have a textbox called "NameTextBox" and "Submit" button in my "index.aspx" page. I need to check whether user entered name in the textbox before clicking submit button. And,...
1
colinod
by: colinod | last post by:
I have the following to determine unused parts of a database and was wondering how to find it if the cell is just empty instead of having the word unused in it <% if...
9
by: PHPstarter | last post by:
Hi people! I'm using $key = in_array('setname', $Sname); echo $key; To try and echo nr 2 in the array here: Because I need a script which can give me the position in the array of a...
0
by: electrical | last post by:
/** Database implements a database of records */ public class Database { private Record base; // the collection of records private int NOT_FOUND = -1; // int used to denote when a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.