您是否期待這樣?確保爲循環中運行時,所有其他陣列count
是一樣的,否則你將得到Notice error
Try this code snippet here
<?php
ini_set('display_errors', 1);
$branchNameList = array("branch_name1", "branch_name2", "branch_name3", "branch_name4");
$branchPhotoList = array("photo1", "photo2", "photo3", "photo4");
$branchAddList = array("address1", "address2", "address3", "address4");
$branchMapList = array("maplink1", "maplink2", "maplink3", "maplink4");
$branchTelList = array("branch_tel1", "branch_tel2", "branch_tel3", "branch_tel4");
for($x=0;$x<count($branchNameList);$x++)
{
if(!empty($branchNameList[$x]))
{
echo $branchNameList[$x];
echo PHP_EOL;
}
if(!empty($branchPhotoList[$x]))
{
echo $branchPhotoList[$x];
echo PHP_EOL;
}
if(!empty($branchAddList[$x]))
{
echo $branchAddList[$x];
echo PHP_EOL;
}
if(!empty($branchMapList[$x]))
{
echo $branchMapList[$x];
echo PHP_EOL;
}
if(!empty($branchTelList[$x]))
{
echo $branchTelList[$x];
echo PHP_EOL;
}
}
解決方案2:
<?php
ini_set('display_errors', 1);
$branchNameList = array("branch_name1", "branch_name2", "branch_name3", "branch_name4");
$branchPhotoList = array("photo1", "photo2", "photo3", "photo4");
$branchAddList = array("address1", "address2", "address3", "address4");
$branchMapList = array("maplink1", "maplink2", "maplink3", "maplink4");
$branchTelList = array("branch_tel1", "branch_tel2", "branch_tel3", "branch_tel4");
$completeData= array_merge(
array("branchNameList"=>$branchNameList),
array("branchPhotoList"=>$branchPhotoList),
array("branchAddList"=>$branchAddList),
array("branchMapList"=>$branchMapList),
array("branchTelList"=>$branchTelList)
);
for($x=0;$x<count($completeData["branchNameList"]);$x++)
{
if(empty($completeData["branchNameList"][$x])||
empty($completeData["branchPhotoList"][$x])||
empty($completeData["branchAddList"][$x])||
empty($completeData["branchMapList"][$x])||
empty($completeData["branchTelList"][$x]))
{
continue;
}
else
{
//do what you want to do.
}
}
只是用於循環 – splash58
'我有一個瘋狂的夜晚today' - >因爲你有所有你需要的答案,所以我可以說'現在晚安,享受你的睡眠':) – OldPadawan
是啊謝謝:D @oldpalawan – cryptohustla