thirdphase Posted May 22, 2011 Share Posted May 22, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/237152-using-count-with-arrays/ Share on other sites More sharing options...
mgoodman Posted May 22, 2011 Share Posted May 22, 2011 Check out the array_count_values function. If I understand your question correctly then it does exactly what you're trying to do. array_count_values Quote Link to comment https://forums.phpfreaks.com/topic/237152-using-count-with-arrays/#findComment-1218831 Share on other sites More sharing options...
thirdphase Posted May 22, 2011 Author Share Posted May 22, 2011 Thanks. That worked a treat! Quote Link to comment https://forums.phpfreaks.com/topic/237152-using-count-with-arrays/#findComment-1218844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.