Jump to content

Using count with arrays


thirdphase

Recommended Posts

I have created a basic array by pulling values from a database but now need to count how many of the array values are 0.

 

Here is my code so far:

 

$qty_array = array();

$qty_array[0] = $product_row["WF_qty"];

$qty_array[1] = $product_row["SD_qty"];

$qty_array[2] = $product_row["DD_qty"];

$qty_array[3] = $product_row["CD_qty"];

$qty_array[4] = $product_row["PD_qty"];

$qty_array[5] = $product_row["SP_qty"];

$qty_array[6] = $product_row["VS_qty"];

$qty_array[7] = $product_row["RO_qty"];

$qty_array[8] = $product_row["PO_qty"];

 

$qty_count = count($qty_array);

 

This is returning the value 9 as I expected but I am not sure how to change the count function so that I count values that are 0 and ignore the rest.

 

Can anyone help?

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.