PHP 新手.从数组中检索信息


New to php. retrieve information from array

嘿伙计们,我试图从这个数组中检索信息。

Array
(
    [userid] => 1
    [username] => dunkers
    [password] => 699e5fae54df4c82314e42dd86c4d383
    [email] => a.dunkerley7462@student.leedsb
)
Array
(
    [userid] => 2
    [username] => mantis
    [password] => 699e5fae54df4c82314e42dd86c4d383
    [email] => ad481993@hotmail.com
)
Array
(
    [userid] => 190
    [username] => helenanderson94
    [password] => 699e5fae54df4c82314e42dd86c4d383
    [email] => helenandersonnn@hotmail.co.uk
)
Array
(
    [userid] => 191
    [username] => dd
    [password] => 699e5fae54df4c82314e42dd86c4d383
    [email] => dd@dd.com
)

我试图为每个循环制作一个,它只挑选出用户名的值,并且我已经研究了几个小时,每次我尝试它都会提出非法字符串等

 foreach($encodedResults as $row){
    $decode = json_decode($row, true);
    print_r($decode);

这只是一些入门代码,我只是为了将所有信息从数组中提取出来,但我再次只想要用户名的值

像这样:

foreach($encodedResults as $row){
    $decode = json_decode($row, true);
    echo $decode['username'];
}

让它们输出做得很好,下面是一个仅回显用户名的示例。

// Loop through JSON encoded entries
foreach($encodedResults as $row)
{
    // Decode result to an array
    $decode = json_decode($row, true);
    // Echo out the username key in the decode array.
    echo $decode['username'];
}

如果您有任何问题,请告诉我!