为什么我的阵列会这样出现?

时间:2016-11-22 14:14:17

标签: php arrays multidimensional-array

我正在使用数组成功查询数据库,我得到了正确的结果。但由于数组的创建方式,我在使用结果时遇到了困难。

这是OUTPUT:

Array (
[0] => Array (
    [0] => Array (
        [0] => 1@1.1
        )
        [1] => 2@2.2
    )
    [2] => 3@3.3
)

以下是代码的生成方式:

$owners_string = $row['profile_id'];
$owners_stringd = unserialize($owners_string);
foreach ($owners_stringd as $profileid => $valuee) {
    if ($valuee) {
        $sql = "select email from {$mysql_tbl_pre}profile where profile_id = '$valuee' ";
        $err = mysqli_query($estate_db, $sql);
        if (!$err) 
            error_dlg(mysqli_error($estate_db));
        elseif (mysqli_num_rows($err) <= 0) 
            info_dlg("Error");

        while ($row = mysqli_fetch_array($err)) 
            $new_array[$profileid] = $row['email'];

        $new_array = array($new_array);
        foreach ($new_array as $emailvalue)
            $emailsd = print_r($emailvalue, true);

    } else {
        $emailsd = "";
    }
}

我知道如何破坏结果,但是当我确实破坏了这个结果时,就会出现“Array,1 / 1.1”(这封电子邮件是最后一次)。

我需要它是一个完整的结果,例如1 @ 1.1,2 @ 2.2,3 @ 3.3

这是两个单独的表。第一个表存储一串ID,第二个表的每个Id都在它自己的行中,并在一个单独的列中包含一个电子邮件。

来自while循环的解决方案:

while ($thisemail = mysqli_fetch_array($rsz)) {
    $emailsd .= $thisemail['email'] . ',';
}
foreach ($emailsd as $emailvalue)
$email = print_r($emailvalue, true);

0 个答案:

没有答案
相关问题