How can i write an array that holds multiple values for each product

旧街凉风 提交于 2019-12-24 01:11:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!