Jump to content

There has to be a more effiecient way character count


Recommended Posts

Hello,

 

Here is my script

 

It's purpose is to make sure $zip is > 4

 

script

 

<?php

 

 

 

$zcount = str_split($_POST["zip"]);

// where zip is passed from a form//

 

$count = 0;

foreach ($zcount as $letter)

{

  if ($letter == '1' || $letter == '2' || $letter == '3' || $letter == '4' || $letter == '5' || $letter == '6' || $letter == '7' || $letter == '8' || $letter == '9' || $letter == '0' )

  $count++;

}

 

if($count < 5)

                {

    echo "no";

    }

else

    {

                  echo "yes";

    }

 

?>

 

is there an easier way?

 

This is counting every instance of every number individually then adding them together.

 

I actually searched to find the script that i manipulated to that on the forum here, but i figured this may be thread worthy

 

Thanks ???

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.