Ninjakreborn Posted January 23, 2007 Share Posted January 23, 2007 What function can be used in php to check if an array has any values in itIf 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. Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/ Share on other sites More sharing options...
fert Posted January 23, 2007 Share Posted January 23, 2007 http://us2.php.net/manual/en/function.count.phphttp://us2.php.net/manual/en/function.isset.php Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166931 Share on other sites More sharing options...
bibby Posted January 23, 2007 Share Posted January 23, 2007 Or just a dry IF.[code]$a=array();$a[0]=TRUE;$a[1]=TRUE;if($a[5]){ //do something}else{ // there is no $a[5];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166936 Share on other sites More sharing options...
Ninjakreborn Posted January 23, 2007 Author Share Posted January 23, 2007 [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. Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166937 Share on other sites More sharing options...
fert Posted January 23, 2007 Share Posted January 23, 2007 [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]Arrays are variables Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166943 Share on other sites More sharing options...
Ninjakreborn Posted January 23, 2007 Author Share Posted January 23, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166949 Share on other sites More sharing options...
kenrbnsn Posted January 23, 2007 Share Posted January 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166952 Share on other sites More sharing options...
Ninjakreborn Posted January 23, 2007 Author Share Posted January 23, 2007 Ah, good idea. Thanks I will try that out with the array, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/35317-arrays/#findComment-166953 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.