Jump to content

There has to be a more effiecient way character count


jerel

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

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.