问题
I've been searching around php.net, w3schools and youtube for something that has multiple objects like "move1, movie2" where each of those objects has variables like "id, qty, price"
.
I prefer an array were I can leave the qty value empty so I can have the user input it though a <form>
, but I will figure that out once I find a form that fits what I need.
Any kind of help would be much appreciated.
I just need a look at the kind of array I need and if I will be able to apply it to my code and figure out the and action=POST
code later.
回答1:
you can handle this in php (server side) which is more common, and also you can handle in client side with java-script which i do'nt recommand . you can use key-value arrays in php, for example you can easily do as bellow:
$basket[0]['productName']='Movies1';
$basket[0]['qty']=1;
$basket[0]['price']=15;
$basket[1]['productName']='Movies2';
$basket[1]['qty']=2;
$basket[1]['price']=30;
in this way you will have an array which can hold all off required information about your products.
来源:https://stackoverflow.com/questions/52699100/how-can-i-write-an-array-that-holds-multiple-values-for-each-product