这是给出php警告
<?php
$xml = simplexml_load_file("videos.xml") or die("Error: Object creation
Failed");
$videos = array();
foreach( $xml->children() as $video){
$a= $video->Serial;
$b=$video->URI;
$videos[$a] = $b;
}
header('Content-type: application/json');
echo json_encode($videos);
?>
第8行中的非法偏移类型。如何解决?
答案 0 :(得分:3)
使用键为数组赋值。你可以简单地写一下:
user.markModified('polls')
输出:
$files = array();
$files['some_key'] = 'an important value';
$files['another_key'] = 'a value';
$files['key'] = 'an non-important value';
您也可以通过简单地说明Array
(
[some_key] => an important value
[another_key] => a value
[key] => an non-important value
)
来创建数组。
例如:
var[array_key'] = some_value'
输出:
$another['key'] = "WOW... that's cool";
并且......享受......
答案 1 :(得分:1)
对于数组
,实际上PHP非常宽松这就是你要做的事情:
$files = array();
$files['key'] = "value";
然而,即使像索引和关联的混合也会起作用:
<?php
$files = array();
for($i=0; $i < 10; $i++){
if($i%2 ==0){
$files["Test".$i] = $i;
} else {
$files[]=$i;
}
}
echo "<pre>";
print_r($files);
输出:
Array
(
[Test0] => 0
[0] => 1
[Test2] => 2
[1] => 3
[Test4] => 4
[2] => 5
[Test6] => 6
[3] => 7
[Test8] => 8
[4] => 9
)