PHP数组无法正常工作
我在使阵列正常工作时遇到一些问题。我正在从Joomla模板中提取参数,然后在主索引文件中使用它们:以下是我到目前为止得到的: 它保存在一个include文件中,我首先拉入该文件PHP数组无法正常工作,php,joomla,multidimensional-array,joomla3.0,Php,Joomla,Multidimensional Array,Joomla3.0,我在使阵列正常工作时遇到一些问题。我正在从Joomla模板中提取参数,然后在主索引文件中使用它们:以下是我到目前为止得到的: 它保存在一个include文件中,我首先拉入该文件 //Social Icons $tbFacebook = $this->params->get('tbFacebook'); $tbTwitter = $this->params->get('tbTwitter'); $tbGoogle = $this->params->get('tb
//Social Icons
$tbFacebook = $this->params->get('tbFacebook');
$tbTwitter = $this->params->get('tbTwitter');
$tbGoogle = $this->params->get('tbGoogle');
$tbLinkedIn = $this->params->get('tbLinkedIn');
$tbPinterest = $this->params->get('tbPinterest');
$tbYouTube = $this->params->get('tbYouTube');
$tbVimeo = $this->params->get('tbVimeo');
//Check all the text boxes for content and assign array information
//This may be able to be handled differently but for simplicity I left it alone
if ($tbFacebook != null) {
$arrFacebook= array("href" => $tbFacebook, "title" => "Like Us On Facebook", "icon" => "<i class=\"fa fa-facebook".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbTwitter != null) {
$arrTwitter = array("href" => $tbTwitter , "title" => "Follow Us On Twitter", "icon" => "<i class=\"fa fa-twitter".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbGoogle != null) {
$arrGoogle = array("href" => $tbGoogle , "title" => "Follow Us On Google Plus", "icon" => "<i class=\"fa fa-google-plus".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbLinkedIn != null) {
$arrLinkedIn = array("href" => $tbLinkedIn , "title" => "Connect With Us On LinkedIn", "icon" => "<i class=\"fa fa-linkedin".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbPinterest != null) {
$arrPinterest = array("href" => $tbPinterest , "title" => "Pin Us On Pinterest", "icon" => "<i class=\"fa fa-pinterest".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbYouTube != null) {
$arrYouTube = array("href" => $tbYouTube , "title" => "Watch Us On YouTube", "icon" => "<i class=\"fa fa-youtube".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbVimeo != null) {
$arrVimeo = array("href" => $tbVimeo , "title" => "Watch Us On Vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank");
};
//Create Social Array
$arrSocial = array(
$arrFacebook,
$arrTwitter,
$arrGoogle,
$arrLinkedIn,
$arrPinterest,
$arrYouTube,
$arrVimeo
);
//Remove the empties
foreach($arrSocial as $key => $value) {
if (empty($value)) {
unset($arrSocial[$key]);
$arrSocial = array_values($arrSocial);
};
}
//Variable to determine fist item, incase its not phone
$first = true;
//社交图标
$tbFacebook=$this->params->get('tbFacebook');
$tbTwitter=$this->params->get('tbTwitter');
$tbGoogle=$this->params->get('tbGoogle');
$tbLinkedIn=$this->params->get('tbLinkedIn');
$tbPinterest=$this->params->get('tbPinterest');
$tbYouTube=$this->params->get('tbYouTube');
$tbVimeo=$this->params->get('tbVimeo');
//选中所有文本框中的内容并指定数组信息
//这可能会以不同的方式处理,但为了简单起见,我不去管它
如果($tbFacebook!=null){
$arrFacebook=array(“href”=>$tbFacebook,“title”=>“像我们一样在Facebook上”,“icon”=>,“target”=>“blank”);
};
如果($tbTwitter!=null){
$arrTwitter=array(“href”=>$tbTwitter,“标题”=>“在Twitter上关注我们”、“图标”=>”、“目标”=>“空白”);
};
如果($tbGoogle!=null){
$arrgool=array(“href”=>$tbGoogle,“title”=>“在Google Plus上关注我们”、“icon”=>”、“target”=>“blank”);
};
如果($tbLinkedIn!=null){
$arrLinkedIn=array(“href”=>$tbLinkedIn,“title”=>“在LinkedIn上与我们联系”,“icon”=>”,“target”=>“blank”);
};
如果($tbPinterest!=null){
$arrPinterest=array(“href”=>$tbPinterest,“title”=>“将我们锁定在Pinterest上”、“icon”=>”、“target”=>“blank”);
};
如果($tbYouTube!=null){
$arrYouTube=array(“href”=>$tbYouTube,“title”=>“在YouTube上观看我们”、“icon”=>”、“target”=>“blank”);
};
如果($tbVimeo!=null){
$arrVimeo=array(“href”=>$tbVimeo,“title”=>“在Vimeo上观看我们”,“icon”=>,“target”=>“blank”);
};
//创建社交阵列
$arrSocial=数组(
美元,
$arrTwitter,
美元谷歌,
$arrLinkedIn,
$arrPinterest,
美元,
$arrVimeo
);
//把空瓶移走
foreach($arras$key=>$value){
if(空($value)){
未设置($arrSocial[$key]);
$arrSocial=array_值($arrSocial);
};
}
//变量以确定首项,如果不是电话
$first=true;
我的约姆拉密码
<?php if ($this->countModules('footer_mobile')) : ?>
<jdoc:include type="modules" name="footer_mobile" style="html5" />
<?php else :
//Limit to the first 5 items
for($i=0;$i<5;$i++){
if ( $first ) {
$first = false;
echo '<div class="col-xs-2 col-xs-offset-1"><a href="'.$arrMobileFooter[$i]["href"].'" title="'.$arrMobileFooter[$i]["title"].'" target="_'.$arrMobileFooter[$i]["target"].'" ">'.$arrMobileFooter[$i]["icon"].'</a></div>';
} else {
echo '<div class="col-xs-2"><a href="'.$arrMobileFooter[$i]["href"].'" title="'.$arrMobileFooter[$i]["title"].'" target="_'.$arrMobileFooter[$i]["target"].'">'.$arrMobileFooter[$i]["icon"].'</a></div>';
};
};
endif; ?>
当文件输出时,它只会拉入Facebook链接,即使for循环正在创建其余的链接,但不会填充它:
<div class="col-xs-2 col-xs-offset-1">
<a href="https://www.facebook.com/pages/United-Methodist-Camp-Tekoa-Inc/304907509358" title="Like Us On Facebook" target="_blank">
<i class="fa fa-facebook-square fa-2x"></i>
</a>
</div>
<div class="col-xs-2">
<a href="/" title="" target="_" "=""></a>
</div>
<div class="col-xs-2">
<a href="/" title="" target="_"></a>
</div>
<div class="col-xs-2">
<a href="/" title="" target="_"></a>
</div>
<div class="col-xs-2">
<a href="/" title="" target="_"></a>
</div>
有人能告诉我我做错了什么吗?我想问题是当你试图在
foreach
中操纵$arrSocial
时。我建议您重写此命令,并且仅当对象不是null
时,才使用$arrSocial[]=value
将其添加到现有数组中
试试这个:
//Social Icons
$tbFacebook = $this->params->get('tbFacebook');
$tbTwitter = $this->params->get('tbTwitter');
$tbGoogle = $this->params->get('tbGoogle');
$tbLinkedIn = $this->params->get('tbLinkedIn');
$tbPinterest = $this->params->get('tbPinterest');
$tbYouTube = $this->params->get('tbYouTube');
$tbVimeo = $this->params->get('tbVimeo');
$arrSocial = array();
if ($tbFacebook != null) {
$arrSocial[] = array("href" => $tbFacebook, "title" => "Like Us On Facebook", "icon" => "<i class=\"fa fa-facebook".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbTwitter != null) {
$arrSocial[] = array("href" => $tbTwitter , "title" => "Follow Us On Twitter", "icon" => "<i class=\"fa fa-twitter".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbGoogle != null) {
$arrSocial[] = array("href" => $tbGoogle , "title" => "Follow Us On Google Plus", "icon" => "<i class=\"fa fa-google-plus".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbLinkedIn != null) {
$arrSocial[] = array("href" => $tbLinkedIn , "title" => "Connect With Us On LinkedIn", "icon" => "<i class=\"fa fa-linkedin".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbPinterest != null) {
$arrPinterest = array("href" => $tbPinterest , "title" => "Pin Us On Pinterest", "icon" => "<i class=\"fa fa-pinterest".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbYouTube != null) {
$arrSocial[] = array("href" => $tbYouTube , "title" => "Watch Us On YouTube", "icon" => "<i class=\"fa fa-youtube".$varSquare." fa-2x\"></i>", "target" => "blank");
};
if ($tbVimeo != null) {
$arrSocial[] = array("href" => $tbVimeo , "title" => "Watch Us On Vimeo", "icon" => "<i class=\"fa fa-vimeo-square fa-2x\"></i>", "target" => "blank");
};
//社交图标
$tbFacebook=$this->params->get('tbFacebook');
$tbTwitter=$this->params->get('tbTwitter');
$tbGoogle=$this->params->get('tbGoogle');
$tbLinkedIn=$this->params->get('tbLinkedIn');
$tbPinterest=$this->params->get('tbPinterest');
$tbYouTube=$this->params->get('tbYouTube');
$tbVimeo=$this->params->get('tbVimeo');
$arrSocial=array();
如果($tbFacebook!=null){
$arrSocial[]=array(“href”=>$tbFacebook,“title”=>“喜欢我们在Facebook上”、“icon”=>”、“target”=>“blank”);
};
如果($tbTwitter!=null){
$arrSocial[]=array(“href”=>$tbTwitter,“title”=>“在Twitter上关注我们”、“icon”=>”、“target”=>“blank”);
};
如果($tbGoogle!=null){
$arrSocial[]=array(“href”=>$tbGoogle,“title”=>“在Google Plus上关注我们”、“icon”=>”、“target”=>“blank”);
};
如果($tbLinkedIn!=null){
$arrSocial[]=array(“href”=>$tbLinkedIn,“title”=>“在LinkedIn上与我们联系”,“icon”=>”,“target”=>“blank”);
};
如果($tbPinterest!=null){
$arrPinterest=array(“href”=>$tbPinterest,“title”=>“将我们锁定在Pinterest上”、“icon”=>”、“target”=>“blank”);
};
如果($tbYouTube!=null){
$arrSocial[]=array(“href”=>$tbYouTube,“title”=>“在YouTube上观看我们”、“icon”=>”、“target”=>“blank”);
};
如果($tbVimeo!=null){
$arrSocial[]=array(“href”=>$tbVimeo,“title”=>“在Vimeo上观看我们”、“icon”=>”、“target”=>“blank”);
};