Php array posts make max value output -


i want shopping cart number of item count. post different value different. please make code shorten , unlimited post can manage max value of number of items.

    if($_post['item_number_9']==9){$y=9;} elseif($_post['item_number_8']==8){$y=8;} elseif($_post['item_number_7']==7){$y=7;} elseif($_post['item_number_6']==6){$y=6;} elseif($_post['item_number_5']==5){$y=5;} elseif($_post['item_number_4']==4){$y=4;} elseif($_post['item_number_3']==3){$y=3;} elseif($_post['item_number_2']==2){$y=2;} elseif($_post['item_number_1']==1){$y=1;}  echo $y; //9 max value of array // want code array , $y maximum post 

foreach($_post $key =>$entrie){   if(strpos($key, "item_number_") === 0){     $y = $entrie;   } } 

this goes through $_post elements. if item_number_ value set $y. asumes there 1 entrie in $_post item_number_ in it, there should 1 entrie holds number of items in cart.


but offerall bad practise. should set $_post['item_number'] , hold number of items in that.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -