Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:27:08+00:00 2026-05-29T16:27:08+00:00

If no messages were found in an array then it is returning 2 instead

  • 0

If no messages were found in an array then it is returning 2 instead of null PHP

I am appending messages to array and calling functions to append array but while calling the functions there were no messages found in array also it is showing them as 2 value those are Array ( [0] => [1] => )

$errorMessages = array ();

    $isError = false;
    $middleName = $_POST [ 'middleName' ];
    $middleName = trim( stripslashes( $middleName ) );

    //validation for warrant id
    $warrantId = $_POST [ 'warrantId' ];
    if ( $warrantId == null || ( strlen( $warrantId ) ) <= 0 ) {
        $errorMessages[] = "Warrant Id is required";
    }  else {
        $message = 'enter keyboard characters only for warrant Id.';
        $warrantId = trim( stripslashes( $warrantId ) );
        $x = checkLength($warrantId, 'WarrantId', 1);
        $errorMessages[] = $x;

        //$errorMessages[] = checkRegEx( $warrantId, '/^([a-zA-Z0-9._\- #,^&`~<>:!@$(){}\"\';\*\[\]?%| \n \r \t]*)$/', $message );
    }

    $errorMsg = count($errorMessages);
    print_r($errorMsg);

functions

/*
* Checks the field length is not greater than allowed length
* @params unknown values $fieldValue, $fieldName, $maxLength
* @return tables rows $rowResponse
*/
function checkLength($fieldValue, $fieldName, $maxLength) { 
    $errorMsg = NULL;
if (strlen ( $fieldValue ) > $maxLength) {

    $errorMsg = $fieldName . " cannot be greater than " . $maxLength . " characters.";
}   
return $errorMsg;   
}

/*
* Checks the given field value to match with regular expression or not
* @params unknown values $fieldValue, $mask, $message
* @return tables rows $rowResponse
*/
function checkRegEx($fieldValue, $regEx, $message) {
    $errorMsg = NULL;
if (! (preg_match ( $regEx, $fieldValue ))) {
    $errorMsg =  $message;
}

return $errorMsg;   
}

if no messages are found in array then also it is returning it as 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:27:09+00:00Added an answer on May 29, 2026 at 4:27 pm

    the checkLength and checkRegEx functions are returning NULL and adding that to the array. You should only assign the result of the function calls if they do not return NULL.

    $x = checkLength($warrantId, 'WarrantId', 1);
    if ($x !== NULL) {
        $errorMessages[] = $x;
    }
    
    $x = checkRegEx( $warrantId, '/^([a-zA-Z0-9._\- #,^&`~<>:!@$(){}\"\';\*\[\]?%| \n \r \t]*)$/', $message );
    if ($x !== NULL) {
        $errorMessages[] = $x;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently found out that PHP not only has the fsock* functions, but also
I've gone through the Facebooker msg archive, google, etc and found a couple messages
My application sends SMS messages to people, but the numbers entered in as their
Disclaimer: on SO I found many similar questions and some answers but none solved
I try to add a byte to an array as shown below: messagedata.Add((byte)0xF0); But
OK let's say I have an array filled with {tube, are, fun} and then
I looked in the Rails docs under inflector and found this message... Module deprecated
I have Ubuntu Linux. I found one command will let me download unread message
How many messages does the queue for a standard window hold? What happens when
I have some EDI messages (X12, HL7, etc ...) stored in an Oracle database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.