PHP 数组 - 选择其中的 1 个部分


PHP Array - Selecting 1 part of it

这可能会被某人看到并能够说......这位使它工作/更改它,但它会工作...

我在数据库中存储了一个数组,作为

item1title:::item1product:::item1code###iten2title:::item2product:::item2code etc

但是,我不能只抓住数组的 1 个部分......

  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>';
    }
}