1 2 | class Dictionary { } |
1 2 3 | $obj1 = new Dictionary(); $obj2 = new Dictionary(); $obj3 = new Dictionary(); |
1 2 3 4 | class Dictionary { public $translations = array(); public $type ="En"; } |
1 2 3 4 5 6 7 8 9 10 | $en = new Dictionary(); print_r( $en ); 如果运行该脚本,将看到如下对象的输出: Dictionary Object ( [translations] => Array ( ) [type] => En ) |
1 2 3 4 5 6 7 8 9 | $en = new Dictionary(); $en->translations['TREE'] = "tree"; $fr = new Dictionary(); $fr->type = "Fr"; $fr->translations['TREE'] = "arbre"; foreach ( array( $en, $fr ) as $dict ) { print "type: {$dict->type} "; print "TREE: {$dict->translations['TREE']}\n"; } |
1 2 | type: En TREE: tree type: Fr TREE: arbre |
1 2 3 4 5 6 7 8 | $en = array( 'translations'=>array( 'TREE' => 'tree' ), 'type'=>'En' ); $fr = array( 'translations'=>array( 'TREE' => 'arbre' ), 'type'=>'Fr' ); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |