2014-05-24 19:09
浏览 32


I'm studying how objects and arrays work in PHP for a little project. Unfortunately it's difficult to find out what are good ways to deal with data, there are many solutions but i can't find the right solution for my problem. I think I prefer two work with an object.

I have two questions related to this example:

class cars {}

$cars = new cars();  

$cars->brand = new cars();
$cars->brand->audi = "A6";
$cars->brand->opel = "insignia";

question 1 How can I get each brand as output for example with a for each loop or other function?

echo somesolution will give audi

question 2 Is there a way like with arrays using parentheses to write the code without repeating $cars->brand->opel ?

question 3 Why do I need tho create the class cars?

图片转代码服务由CSDN问答提供 功能建议

我正在研究对象和数组如何在PHP中为一个小项目工作。 不幸的是,很难找到处理数据的好方法,有很多解决方案,但我找不到适合我的问题的解决方案。 我想我更喜欢用对象做两件事。


  class cars {} 
 $ cars = new cars();  
 $ cars-> brand = new cars(); 
 $ cars-> brand-> audi =“A6”; 
 $ cars-> brand-> opel =“insignia”;  

问题1 如何以每个循环或其他功能为例,如何将每个品牌作为输出? \ n

echo somesolution将给出audi

问题2 是否有类似于使用括号的数组编写代码而不重复 $ cars-> brand-> opel

问题3 为什么我需要创建班车?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题