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