Jump to content

size of array


deansaddigh

Recommended Posts

Hi,

 

How would i do a size of array calculation so that i can conditionally do something.

 

For example

$discounts = $_POST["discounts"];
$sizeof_arr = sizeof($discounts);

if ( sizeof_arr >0 )
{
        }
        else
        {
        }

 

Does not work, get this error

 

 

Notice: Use of undefined constant sizeof_arr - assumed 'sizeof_arr' in \\nas44ent\domains\l\languageschoolsuk.com\user\htdocs\admin\add_course_form_submit.php on line 22

 

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/197018-size-of-array/
Share on other sites

Hi,

 

How would i do a size of array calculation so that i can conditionally do something.

 

For example

$discounts = $_POST["discounts"];
$sizeof_arr = sizeof($discounts);

if ( sizeof_arr >0 )
{
        }
        else
        {
        }

 

Does not work, get this error

 

 

Notice: Use of undefined constant sizeof_arr - assumed 'sizeof_arr' in \\nas44ent\domains\l\languageschoolsuk.com\user\htdocs\admin\add_course_form_submit.php on line 22

 

 

Thanks in advance

 

You forgot your $ in front of your variable:

$discounts = $_POST["discounts"];
$sizeof_arr = sizeof($discounts);

if ( $sizeof_arr >0 ) // <--- Right here
{
        }
        else
        {
        }

Link to comment
https://forums.phpfreaks.com/topic/197018-size-of-array/#findComment-1034262
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.