gpt4 book ai didi

php - 根据 if 语句条件分配字符串数组内容

转载 作者:行者123 更新时间:2023-12-04 05:41:44 25 4
gpt4 key购买 nike

我需要将不同的表标记代码作为字符串存储在 php 数组中。一些需要存储在数组中的代码需要使用 if 语句进行测试。在我知道我需要以这种方式测试某些代码之前,一切都完美无缺,但是现在我知道存储的字符串基于“if 语句”,我不确定如何对其进行编码。因为我需要结束 的标记当前 slot 以插入 php 条件语句。结果,我无法继续在“当前”插槽中存储数据,这正是我所需要的。

一个多小时以来,我一直在努力寻找解决方法,感谢您对此的任何帮助。

$favorites[] = '
<tr>
<td><a href="#">'.$files_row['name'].'</a></td>
<td><a href="#"><img class="table-button" src="images/smallglobe.png"></a></td>
<td>
<img src="images/e-mail-icon.PNG">';
if(strcmp($_files_row['email'],'none') != 0){
$favorites[] = '<div style="display:none;"><a href="#" >'.$files_row['email'].'</a></div>';
}
$favorites[]='
</td>
<td class="table-button-cell">
<img class="table-button" src="images/eicon.png">
<div class="phonepopup" style="display:none;">Call: '.$files_row['phone'].'</div>
</td>
<td class="table-button-cell"> .... etc....

最佳答案

在评估 if 语句后,尝试为当前槽使用临时变量并将其分配给数组。所以你可以连接必要的字符串:

$temp_var = '
<tr>
<td><a href="#">'.$files_row['name'].'</a></td>
<td><a href="#"><img class="table-button" src="images/smallglobe.png"></a></td>
<td>
<img src="images/e-mail-icon.PNG">';
if(strcmp($_files_row['email'],'none') != 0){
$temp_var .= '<div style="display:none;"><a href="#" >'.$files_row['email'].'</a></div>';
}
$temp_var .='
</td>
<td class="table-button-cell">
<img class="table-button" src="images/eicon.png">
<div class="phonepopup" style="display:none;">Call: '.$files_row['phone'].'</div>
</td>
<td class="table-button-cell"> .... etc....';

$favorites[] = $temp_var;

关于php - 根据 if 语句条件分配字符串数组内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11179374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com