Jump to content

arrays


Ninjakreborn

Recommended Posts

What function can be used in php to check if an array has any values in it
If you create an empty array (error for instance)
and then register variables into the array as needed, how do you later check to see if the array is empty or has some variables in it.  If it's not empty, I then want to go ahead and display all the errors.
Link to comment
Share on other sites

[quote]Warning:  isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.[/quote]
As far as count, I could, but I am wondering is there another function.  I could count what is in the array, and hten say something like if ($arraycount != 0)
or something, but I want something simpler, something built in.  That's why I ask, is there a function for array's, that will just simply check if there are values in the array, or if the array is empty?

[quote]$a=array();
$a[0]=TRUE;
$a[1]=TRUE;


if($a[5])
{
    //do something
}
else
{
    // there is no $a[5];
}[/quote]

That wouldn't help either, as it's part of a system I am building.  It is a way to include parameters into something, I have to be able to test if any where entered, if none do something, if not do something else.
Link to comment
Share on other sites

So
$temp = array("parameter1", "Parameter2", "Parameter3");
if (isset($temp)) {
// $temp is an array and has some variabbles passed to it, which are param 1, 2, and 3
}else {
// $temp is an array in nature, but DOES NOT have any values pass to it whatsoever at the moment
}

Is the above statement 100% correct, that you know of?
Link to comment
Share on other sites

Just use the [url=http://www.php.net/empty]empty()[/url] function.

[code]<?php
$ary = array();
if (empty($ary)) echo 'The array $ary is empty<br>';
$ary[] = 'not empty';
if (empty($ary)) echo 'The array $ary is empty';
else echo 'The array $ary is <span style="font-weight:bold">not</span> empty';
?>[/code]

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.