创建与对象关联的div [英] Create divs associated to objects

查看:94
本文介绍了创建与对象关联的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前问过一个类似的问题,但是我没有找到任何帮助我的东西。

I asked a similar question earlier but I haven't been able to find anything to help me. I have now updated my code to something working but I am now completely stuck.

这是我的php代码:

class person {
    public $name;
    public $SE;
    private $SD;

    function __construct ( $n, $s1, $s2 ) {
        $this->name = $n;
        $this->SE = $s1;
        $this->SD = $s2;
    }
}

$Obj = new person ( "ExampleName", 5, 5 );

我需要为每个人创建单独的div,在这些div中包含他们的名字。我的主要问题是,在创建这些div后,我需要让它们以特定的方式排序(这对你没有任何重要性),这需要每个div有一个ID与创建div的原始人相关联。

I need to have seperate divs created for each person, containing their names in these divs. My main problem is that after these divs are created I need to have them sorted in a particular way (that isn't any importance to you) that requires for each div to have a ID associated to the original person from which the div was created.

我可以从名称列表创建div,但不能从对象创建。
所以:

I am otherwise able to create divs from a list of names but not from objects. So:


  1. 我需要一种方法来使用foreach循环根据每个对象(人)创建div。

  1. I need a way to use foreach loops to create divs according to each object (person).

我需要与此人相关联的这些div。

I need these divs associated with (linked to) that person.

感谢任何帮助

推荐答案

不知道与此人相关的div是什么意思,第一个问题这应该工作。

Not sure what you mean by divs associated with that person but for first problem this should work.

假设你有一个名为$ objs的对象数组

Lets say you have an array of objects named $objs

foreach($objs as $obj)
{
   echo "<div>".$obj->name."</div>";
}

这篇关于创建与对象关联的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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