我如何编写一个数组来为每个产品保存多个值 [英] How can i write an array that holds multiple values for each product

查看:22
本文介绍了我如何编写一个数组来为每个产品保存多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在 php.net、w3schools 和 youtube 上搜索具有多个对象的内容,例如move1、movie2",其中每个对象都有诸如 id、qty、price"之类的变量.

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".

我更喜欢一个数组,我可以将 qty 值留空,这样我就可以让用户通过 <form> 输入它,但是一旦我找到适合的表单,我就会弄清楚我需要的.

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.

我只需要看看我需要的数组类型,以及我是否能够将它应用到我的代码中并在以后找出 action=POST 代码.

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.

推荐答案

你可以在更常见的 php(服务器端)中处理这个问题,你也可以在客户端使用我不推荐的 java-script 来处理.您可以在 php 中使用键值数组,例如您可以轻松地执行以下操作:

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.

这篇关于我如何编写一个数组来为每个产品保存多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆