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

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

问题描述

我一直在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脚本进行处理. 您可以在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天全站免登陆