Jump to content

[SOLVED] array problem


shadiadiph

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.