添加数组PHP时遇到问题
我正在学习编程,似乎不知道如何附加以下数组。这里有一个片段添加数组PHP时遇到问题,php,arrays,append,push,Php,Arrays,Append,Push,我正在学习编程,似乎不知道如何附加以下数组。这里有一个片段 <?php $dir = "./media/"; if($dh = opendir($dir)) { while(false != ($file = readdir($dh))) { if($file != "." && $file != "..") { $pathinfo = pathinfo($file); $pathinfo
<?php
$dir = "./media/";
if($dh = opendir($dir))
{
while(false != ($file = readdir($dh)))
{
if($file != "." && $file != "..")
{
$pathinfo = pathinfo($file);
$pathinfo = $pathinfo['filename'];
$mp3 = "http://localhost/media/" . $file;
$Obj1 = ["title=" => $pathinfo,
"artist=" => "artist1",
"mp3=" => $mp3];
$Obj2 = append($Obj1);
}
}
closedir($dh);
}
?>
我不明白为什么这样不行。感谢您的帮助。谢谢 你在检查为什么覆盖我的编辑?我不是故意的。我只是注意到我没有包括我不是故意的。我只是注意到我忘记了Ok。我把你错过的最后两行缩进了。所有代码至少需要4个空格才能正确缩进。非常感谢您的帮助!
$dir = "./media/";
// Always initialize your array
$array = array();
if ( $dh = opendir($dir) ) {
while ( false != ( $file = readdir($dh) ) ) {
if ( $file != "." && $file != ".." ) {
$pathinfo = pathinfo($file);
$pathinfo = $pathinfo['filename'];
$mp3 = "http://localhost/media/" . $file;
// Don't do silly things like putting "=" in every key
$thisArray = array(
'title' => $pathinfo,
'artist' => 'artist1',
'mp3' => $mp3
);
$array[] = $thisArray;
// Or $array += $thisArray;
}
}
closedir($dh);
}