I am in the process of making a shopping cart for my website, and have each item in the cart as a multidimensional array. One of the elements in it is 'ordered', which has the quantity being ordered. Is there any way to delete the array element if the quantity ordered is 0? Thanks in advance!
function array_del($str,&$array) { // Remove a variable from an array. Example usage: array_del($str,$array); if (in_array($str,$array)==true) { foreach ($array as $key=>$value) { if ($value==$str) unset($array[$key]); } } } PHP: Not sure if it's what you wanted
A slightly faster way to do the same as above would be: function del_array($str, array &$array) { if (($key = array_search($str, $array)) !== false) { unset($array[$key]); } } PHP: