我试图将每个故事导入一个对象.每个对象将具有多个字符串(开始和结束)以及从附加内容中的内容生成的数组.一个小例子是:
<feed>
<story>
<run>
<start>1/1/2012</start>
<end>3/1/2012</end>
</run>
<additional-content>
<content>
<sample>Sample story example</sample>
</content>
<content>
<sample>Sample story example</sample>
</content>
</additional-content>
</story>
...
</feed>
Run Code Online (Sandbox Code Playgroud)
我将所有xml导入到字符串中.另外,我试图在没有库的情况下这样做.我理解循环每个故事,但不确定如何将内容加载到对象中,同时还正确生成数组.任何帮助,将不胜感激.
我正在寻找一种纯粹的CSS方式来将图像置于文本段落中,以便文本包裹在图像的两侧.
Ideely the image |-----| would be placed
before or after |-img-| the text within
the code structure|-----| and the text
would wrap around the image.
Run Code Online (Sandbox Code Playgroud) 我试图在一个单独的函数中引用一个已定义的常量.我得到的错误是指未定义的变量,以及为每个FOO和BAR定义为常量的变量.
class Boo {
public function runScare() {
$this->nowScaring('FOO');
$this->nowScaring('BAR');
}
private function nowScaring($personRequest) {
define ('FOO', "test foo");
define ('BAR', "test bar");
$person = ${$personRequest};
echo "<br/>Query selected is: " . $person . "<br/>";
}
}
$scare = new Boo;
$scare->runScare();
Run Code Online (Sandbox Code Playgroud) 我试图将关联数组转换为对象数组.
$assoc = array (
array(
'prop1'=>'val1',
'prop2'=>'val2',
),
array(
'prop1'=>'val1',
'prop2'=>'val2',
),
)
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的代码:
class Assoc {
public function setObject($assoc) {
$this->assoc[] = new Obj($assoc);
}
}
class Obj {
public function __construct($item) {
foreach ( $item as $property=>$value ) {
$this->{$property} = $value;
}
}
}
$test = New Assoc();
$test->setObject($assoc);
Run Code Online (Sandbox Code Playgroud)
此代码适用于单个数组,但不适用于数组数组.如果你可以帮助我认为是setObject函数中的循环.