array(2) {
[0]=>
object(stdClass)#144 (7) {
["id"]=>
string(1) "2"
["name"]=>
string(8) "name1"
["value"]=>
string(22) "Lorem Ipsum Dolar Amet"
["type"]=>
string(8) "textarea"
["group"]=>
string(1) "1"
["published"]=>
string(1) "1"
["ordering"]=>
string(1) "1"
}
[1]=>
object(stdClass)#145 (7) {
["id"]=>
string(1) "4"
["name"]=>
string(6) "Link1"
["value"]=>
string(36) "abcabcab"
["type"]=>
string(4) "link"
["group"]=>
string(1) "1"
["published"]=>
string(1) "1"
["ordering"]=>
string(1) "2"
}
}
我想只打印id = 4的“value”(abcabcab)。我怎样才能做到这一点?
答案 0 :(得分:2)
foreach($array as $row){
if($row['id']==4){
print($row['value']);
}
}
答案 1 :(得分:1)
array_walk($a, function($el){if($el->id === 4){print $el->value;}});
答案 2 :(得分:1)
foreach ($array as $entry) {
if ($entry['id'] == 4)
echo $entry['value'];
}
答案 3 :(得分:1)
这有效:
foreach ($array as $entry) {
if ($entry->id == 4)
echo $entry->value;
}
谢谢!