shadiadiph Posted May 14, 2009 Share Posted May 14, 2009 I have the following array $keywords which is made up of $keyword1 to 4 if $keyword1 to 4 are empty I want $errorkeyword to be yes how can i do this ? At the moment i have tried the following but it it obviously wrong ?? $keywords=''; $keywords= array($keyword1,$keyword2,$keyword3,$keyword4); if ($keywords==false) { $action="addtext"; $errorkeyword="yes"; } Link to comment https://forums.phpfreaks.com/topic/158109-solved-array-problem/ Share on other sites More sharing options...
shadiadiph Posted May 14, 2009 Author Share Posted May 14, 2009 tried this also doesn't work $keywords=''; $keywords= array($keyword1,$keyword2,$keyword3,$keyword4); if (!isset($keywords)) { $action="addtext"; $errorkeyword="yes"; } Link to comment https://forums.phpfreaks.com/topic/158109-solved-array-problem/#findComment-833995 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 Do you want the error keyword to be yes if all of the array elements are empty? Or just if one of them is empty? Also with the second way you have done it, isset will be true as you have put something into the array even if it is null. So there array would look some thing like. array[0] = null array[1] = null array[2] = null array[3] = null etc.. you need to individualy test each array element <?php foreach ($keywords as $key=>$value) { if($value == null) { $errorkeyword="yes"; break; } } ?> this will set errorketword to yes if one of the keys is null Link to comment https://forums.phpfreaks.com/topic/158109-solved-array-problem/#findComment-834012 Share on other sites More sharing options...
shadiadiph Posted May 14, 2009 Author Share Posted May 14, 2009 thankyou that was driving me nuts Link to comment https://forums.phpfreaks.com/topic/158109-solved-array-problem/#findComment-834014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.