如何从PHP中的关联数组中打印值?

时间:2016-10-20 22:03:15

标签: php arrays multidimensional-array

我遇到以下代码问题:

w = widgets.Dropdown(
    options=['Addition', 'Multiplication', 'Subtraction'],
    value='Addition',
    description='Task:',
)

def on_change(change):
    if change['type'] == 'change' and change['name'] == 'value':
        print "changed to %s" % change['new']

w.observe(on_change)

display(w)

在此之前,一切似乎都很好:

# THIS FUNCTION CONNECTS TO MY DATABASE
function createSQLconnection(&$connection) {
    $connection = mysqli_connect("typical", "yaddayadda", "crap");
    // mysql_select_db("db", $connection);
    if (!$connection) {
        return "500";
    } else {
        return "200";
    }
}

# THIS FUNCTION GETS ALL LOGS FROM MY DATABASE
function getLogs($conn, &$list, &$length) {
    $sql = 'SELECT * FROM `db`.`logs`';
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        $i = 0;
        while($row=mysqli_fetch_assoc($result)) {
            $list[$i] = $row;
            $i++;
        }
        $length = $i;
    }
}

createSQLconnection($conn);
getLogs($conn, $logList, $logLength);

完全没有错误,没有问题,只有没有文字。

当我转储数组时,更令人困惑的是:

for($row=0; $row<$logLength; $row++) {
    echo $logList['photo_id'][$row];
    echo $logList['name'][$row];
    echo $logList['location'][$row];
}

一切都很好:

print_r($logList);

我真的不明白。应该这么简单。难道我做错了什么?我可能错过了什么?

0 个答案:

没有答案