也许它重复但我找不到。
something = new ArrayList<>();
something.add(new Object("Hello"));
something.add(new object("World"));
something.add(new Object("!"));
for(blablabla){
System.out.print(something.get(i).getTextFromConstructor());
}
这将打印“Hello World!”
在PHP中我不知道解决方案将整个对象传递到数组中以从循环调用他们的方法或仅仅通过某些东西[0] - &gt; method(); 我知道这在php中无法完成,但也许我错了: - )谢谢
答案 0 :(得分:1)
$arr = array();
$arr[] = new MyUSerDefinedObject("Hello");
//...
echo $arr[0]->methd();
//or
foreach ($arr as $val) {
echo $val->methd();
}
答案 1 :(得分:0)
使用此示例设置网桥b / w php和java,以便您可以将值传递给它们
<?php
$date = new Java("java.util.Date", 70, 9, 4);
var_dump($date->toString());
$map = new Java("java.util.HashMap");
$map->put("title", "Java Bridge!");
$map->put("when", $date);
echo $map->get("when")->toString()."\n";
echo $map->get("title")."\n";
$array = array(1,2,3,4,5);
$map->put("stuff", $array);
var_dump($map->get("stuff"))."\n";
$system = new JavaClass("java.lang.System");
echo "OS: ".$system->getProperty("os.name")."\n";
$math = new JavaClass("java.lang.Math");
echo "PI: ".$math->PI."\n";
?>