[英]PHP Array - Selecting 1 part of it
这可能会由某人查看并可以说...这使它起作用/更改了它,但是它将起作用...
我有一个数组存储在数据库中为
item1title:::item1product:::item1code###iten2title:::item2product:::item2code etc
但是,我不能用...仅抓住阵列的一部分。
if(isset($itemConversations) && !empty($itemConversations)){
$mAttributes = array();
if(strpos($item['itemConversations'], "###") !== false){
$mAttributes = explode("###", $item['itemConversations']);
} else {
$mAttributes[] = $item['itemConversations'];
}
foreach($mAttributes as &$mAttribute){
if(strpos($mAttribute, ":::") !== false){
$mAttribute = explode(":::", $mAttribute);
} else {
$mAttribute = array($mAttribute, '');
}
$message .= '
<td colspan="2">hello'.$mAttribute[0].$mAttribute[1].$mAttribute[2].'</td>
</tr>';
有人可以告诉我上面的更改是什么,以便我可以在$ message之后用数组的方式进行选择吗?
您的代码已修复:
$message ='';
if(isset($itemConversations) && !empty($itemConversations)){
$mAttributes = array();
if(strpos($itemConversations, "###") !== false){
$mAttributes = explode("###", $itemConversations);
} else {
$mAttributes[] = $itemConversations;
}
foreach($mAttributes as &$mAttribute){
if(strpos($mAttribute, ":::") !== false){
$mAttribute = explode(":::", $mAttribute);
} else {
$mAttribute = array($mAttribute, '');
}
$message .= '<tr>
<td colspan="2">hello'.$mAttribute[0].$mAttribute[1].$mAttribute[2].'</td>
</tr>';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.