如何在php中为循环创建多数组或数组



但我得到了这个错误分析错误:语法错误,意外的'=',在中应为'('我不知道如何处理这个问题,有人可以推荐这样做的最佳实践吗?

我可以使用很多if-else语句(24(来解决这种类型的方法,但我认为这要简单得多?

感谢

<?php
$streamone = 'streamone.com';
$streamtwo = 'streamtwo.com';
$streamthree = 'streamthree.com';
$streamfour = 'streamfour.com';
$streamfile = array();
if (!empty($streamone)){
$streamfile[] = $streamone;
}
if (!empty($streamsb)){
$streamfile[] = $streamtwo;
}
if (!empty($streamtwo)){
$streamfile[] = $streamthree;
}
if (!empty($streamthree)){
$streamfile[] = $streamfour;
}

$count = count($streamfile);
$streamzz = array();
for ($i = 0;  $i < $count; $i++ ){
$a=1;
$streamzz[] = array( "name" = > "Server $a" ,"select" => "iframe",  "idioma" => "",  "url" => "$streamfile[$i]");
$a++;
}
print_r($streamzz);
/*
output I want to have is
$streamzz = 
array ( "name" => "Server 1", "select" => "iframe",  "idioma" => "",  "url" => "$streamone"),
array ( "name" => "Server 2", "select" => "iframe",  "idioma" => "",  "url" => "$streamtwo"),
array ( "name" => "Server 3", "select" => "iframe",  "idioma" => "",  "url" => "$streamthree"),
array ( "name" => "Server 4", "select" => "iframe",  "idioma" => "",  "url" => "$streamfour"),

*/

尝试删除此行上的空格:

$streamzz[] = array( "name" = > "Server $a" ,"select" => "iframe",  "idioma" => "",  "url" => "$streamfile[$i]");

= >应该是=>

相关内容

  • 没有找到相关文章

最新更新